home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / gcc260diffs.lha / gnu / src-patches / binutils-1.8.x.diffs next >
Encoding:
Text File  |  1994-07-30  |  87.6 KB  |  3,371 lines

  1. diff -2rcN binutils-1.8.x/Makefile binutils-1.8.x-amiga/Makefile
  2. *** binutils-1.8.x/Makefile    Wed Nov 27 22:48:58 1991
  3. --- binutils-1.8.x-amiga/Makefile    Mon Jul 18 23:46:58 1994
  4. ***************
  5. *** 20,26 ****
  6.   
  7.   
  8. ! GNUCC = gcc -O
  9. ! #CC = gcc -O
  10. ! bindir=/usr/local/bin
  11.   
  12.   # for BSD systems
  13. --- 20,36 ----
  14.   
  15.   
  16. ! GNUCC = gcc 
  17. ! bindir=/gnu/bin
  18. ! # for AmigaDOS systems
  19. ! CFLAGS = -O2
  20. ! LDFLAGS = -s
  21. ! # for AmigaDOS Cross-Compiler
  22. ! # CFLAGS = -O2 -DMCH_AMIGA -DCROSS_LINKER
  23. ! # Don't include gprof.
  24. ! PROGS = $(archpfx)ld $(archpfx)size \
  25. !         $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
  26. ! CC = gcc
  27. ! bindir=/gnu/bin
  28.   
  29.   # for BSD systems
  30. ***************
  31. *** 30,35 ****
  32.   # on most systems (trouble with N_DATADDR).  I've fixed some of
  33.   # those problems, though.
  34. ! PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
  35. !         $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
  36.   
  37.   # for USG systems using COFF_ENCAPSULATE
  38. --- 40,45 ----
  39.   # on most systems (trouble with N_DATADDR).  I've fixed some of
  40.   # those problems, though.
  41. ! #PROGS = $(archpfx)gprof $(archpfx)ld $(archpfx)size \
  42. ! #        $(archpfx)nm $(archpfx)strip $(archpfx)ar $(archpfx)ranlib
  43.   
  44.   # for USG systems using COFF_ENCAPSULATE
  45. ***************
  46. *** 37,43 ****
  47.   # Note that you should leave a copy of `ar' in this directory
  48.   # after you install it, since `ranlib' will try to run it from here.
  49. ! CFLAGS = -DWYSE -DUSG -DCOFF_ENCAPSULATE -DPORTAR -DNON_NATIVE -DPIGNAL_MISSING
  50. ! PROGS = ld size nm strip ar robotussin objdump ranlib gprof
  51. ! SIGNAME = signame.o
  52.   # On ALTOS systems, add -DALTOS to CFLAGS.
  53.   
  54. --- 47,53 ----
  55.   # Note that you should leave a copy of `ar' in this directory
  56.   # after you install it, since `ranlib' will try to run it from here.
  57. ! #CFLAGS = -g -DUSG -DCOFF_ENCAPSULATE -DPORTAR -DNON_NATIVE -DPIGNAL_MISSING
  58. ! #PROGS = ld size nm strip ar robotussin objdump ranlib gprof
  59. ! #SIGNAME = signame.o
  60.   # On ALTOS systems, add -DALTOS to CFLAGS.
  61.   
  62. ***************
  63. *** 45,49 ****
  64.   #incompatiable functions from -lPW (like index()), but if you
  65.   #want to be lazy, uncomment this line
  66. ! ALLOCALIBS = -lPW
  67.   
  68.   # For HP-UX systems
  69. --- 55,59 ----
  70.   #incompatiable functions from -lPW (like index()), but if you
  71.   #want to be lazy, uncomment this line
  72. ! #ALLOCALIBS = -lPW
  73.   
  74.   # For HP-UX systems
  75. ***************
  76. *** 84,88 ****
  77.   CPLUS_DEM = $(archpfx)cplus-dem.o
  78.   
  79. ! LIBS=$(MALLOC) $(ALLOCALIBS) $(SIGNAME)
  80.   
  81.   all: $(PROGS)
  82. --- 94,98 ----
  83.   CPLUS_DEM = $(archpfx)cplus-dem.o
  84.   
  85. ! LIBS=$(ALLOCALIBS) $(SIGNAME)
  86.   
  87.   all: $(PROGS)
  88. ***************
  89. *** 91,111 ****
  90.   # LIBS is used here since ld needs to use alloca.
  91.   # Alternatively, compile it with GNU C--then the compiler handles alloca.
  92. !     $(CC) $(CFLAGS) -o $(archpfx)ld $(archpfx)ld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
  93.   
  94.   $(archpfx)size: $(archpfx)size.o
  95. !     $(CC) $(CFLAGS) -o $(archpfx)size $(archpfx)size.o
  96.   
  97.   $(archpfx)nm: $(archpfx)nm.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(MALLOC)
  98. !     $(CC) $(CFLAGS) -o $(archpfx)nm $(archpfx)nm.o \
  99.           $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS) $(MALLOC)
  100.   
  101.   $(archpfx)strip: $(archpfx)strip.o $(GNU_GETOPT_LONG)
  102. !     $(CC) $(CFLAGS) -o $(archpfx)strip $(archpfx)strip.o $(GNU_GETOPT_LONG) $(LIBS)
  103.   
  104.   $(archpfx)ar: $(archpfx)ar.o
  105. !     $(CC) $(CFLAGS) -o $(archpfx)ar $(archpfx)ar.o $(LIBS)
  106.   
  107.   $(archpfx)gprof: $(archpfx)gprof.o $(GNU_GETOPT_LONG) $(CPLUS_DEM)
  108. !     $(GNUCC) $(CFLAGS) -o $(archpfx)gprof $(archpfx)gprof.o \
  109.           $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
  110.   $(archpfx)gprof.o: gprof.c gmon.h 
  111. --- 101,121 ----
  112.   # LIBS is used here since ld needs to use alloca.
  113.   # Alternatively, compile it with GNU C--then the compiler handles alloca.
  114. !     $(CC) $(LDFLAGS) -o $(archpfx)ld $(archpfx)ld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
  115.   
  116.   $(archpfx)size: $(archpfx)size.o
  117. !     $(CC) $(LDFLAGS) -o $(archpfx)size $(archpfx)size.o
  118.   
  119.   $(archpfx)nm: $(archpfx)nm.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(MALLOC)
  120. !     $(CC) $(LDFLAGS) -o $(archpfx)nm $(archpfx)nm.o \
  121.           $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS) $(MALLOC)
  122.   
  123.   $(archpfx)strip: $(archpfx)strip.o $(GNU_GETOPT_LONG)
  124. !     $(CC) $(LDFLAGS) -o $(archpfx)strip $(archpfx)strip.o $(GNU_GETOPT_LONG) $(LIBS)
  125.   
  126.   $(archpfx)ar: $(archpfx)ar.o
  127. !     $(CC) $(LDFLAGS) -o $(archpfx)ar $(archpfx)ar.o $(LIBS)
  128.   
  129.   $(archpfx)gprof: $(archpfx)gprof.o $(GNU_GETOPT_LONG) $(CPLUS_DEM)
  130. !     $(GNUCC) $(LDFLAGS) -o $(archpfx)gprof $(archpfx)gprof.o \
  131.           $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
  132.   $(archpfx)gprof.o: gprof.c gmon.h 
  133. ***************
  134. *** 113,127 ****
  135.   
  136.   $(archpfx)ranlib: $(archpfx)ranlib.o $(GNU_GETOPT_LONG)
  137. !     $(CC) $(CFLAGS) -o $(archpfx)ranlib $(archpfx)ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
  138.   $(archpfx)ranlib.o: ranlib.c
  139. !     $(CC) -c $(CFLAGS) -DAR_PROG=\"/usr/local/gnu/binutils/ar\" ranlib.c $(OUTPUT_OPTION)
  140.   
  141.   $(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
  142. !     $(CC) $(CFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
  143.           $(GNU_GETOPT_LONG) $(LIBS)
  144.   
  145.   # Robotussin is NOT part of `all'.
  146.   $(archpfx)robotussin: $(archpfx)robotussin.o
  147. !     $(CC) $(CFLAGS) -o $(archpfx)robotussin $(archpfx)robotussin.o
  148.   
  149.   libc.a: $(archpfx)robotussin libconvert $(archpfx)ar
  150. --- 123,137 ----
  151.   
  152.   $(archpfx)ranlib: $(archpfx)ranlib.o $(GNU_GETOPT_LONG)
  153. !     $(CC) $(LDFLAGS) -o $(archpfx)ranlib $(archpfx)ranlib.o $(GNU_GETOPT_LONG) $(LIBS)
  154.   $(archpfx)ranlib.o: ranlib.c
  155. !     $(CC) -c $(CFLAGS) -DAR_PROG=\"$(bindir)/ar\" ranlib.c $(OUTPUT_OPTION)
  156.   
  157.   $(archpfx)objdump: $(archpfx)objdump.o $(GNU_GETOPT_LONG) a.out.gnu.h
  158. !     $(CC) $(LDFLAGS) -o $(archpfx)objdump $(archpfx)objdump.o \
  159.           $(GNU_GETOPT_LONG) $(LIBS)
  160.   
  161.   # Robotussin is NOT part of `all'.
  162.   $(archpfx)robotussin: $(archpfx)robotussin.o
  163. !     $(CC) $(LDFLAGS) -o $(archpfx)robotussin $(archpfx)robotussin.o
  164.   
  165.   libc.a: $(archpfx)robotussin libconvert $(archpfx)ar
  166. ***************
  167. *** 146,150 ****
  168.   install: $(PROGS)
  169.       for file in $(PROGS); do \
  170. !     cp $$file $(bindir)/$${file}.new; \
  171. !     mv $(bindir)/$${file}.new $(bindir)/$$file; \
  172.       done
  173. --- 156,161 ----
  174.   install: $(PROGS)
  175.       for file in $(PROGS); do \
  176. !     cp $${file} $(bindir)/$${file}.new; \
  177. !     mv $(bindir)/$${file} $(bindir)/$${file}.bak; \
  178. !     mv $(bindir)/$${file}.new $(bindir)/$${file}; \
  179.       done
  180. diff -2rcN binutils-1.8.x/ar.c binutils-1.8.x-amiga/ar.c
  181. *** binutils-1.8.x/ar.c    Wed Jun 13 05:47:50 1990
  182. --- binutils-1.8.x-amiga/ar.c    Wed Sep 22 12:45:59 1993
  183. ***************
  184. *** 993,996 ****
  185. --- 993,997 ----
  186.     close (outdesc);
  187.   
  188. + #ifndef amigados
  189.     if (!appendflag)
  190.       if (rename (tempname, archive))
  191. ***************
  192. *** 998,1001 ****
  193. --- 999,1011 ----
  194.   
  195.     close_archive ();
  196. + #else
  197. +   /* we *have* to close the file before we rename it, because otherwise
  198. +    * AmigaDOS will just abort with OBJECT_IN_USE_ERROR */
  199. +   close_archive ();
  200. +   if (!appendflag)
  201. +     if (rename (tempname, archive))
  202. +       pfatal_with_name (tempname);
  203. + #endif
  204.   }
  205.   
  206. ***************
  207. *** 1957,1961 ****
  208. --- 1967,1973 ----
  209.        unsigned int size;
  210.   {
  211. + #ifndef __STDC__
  212.     extern char *malloc ();
  213. + #endif
  214.     char *result = malloc (size);
  215.     if (result == 0)
  216. ***************
  217. *** 1969,1973 ****
  218. --- 1981,1987 ----
  219.        unsigned int size;
  220.   {
  221. + #ifndef __STDC__
  222.     extern char *realloc ();
  223. + #endif
  224.     char *result = realloc (ptr, size);
  225.     if (result == 0)
  226. diff -2rcN binutils-1.8.x/cplus-dem.c binutils-1.8.x-amiga/cplus-dem.c
  227. *** binutils-1.8.x/cplus-dem.c    Wed Jun 13 05:42:34 1990
  228. --- binutils-1.8.x-amiga/cplus-dem.c    Wed Sep 22 12:45:32 1993
  229. ***************
  230. *** 49,53 ****
  231.   
  232.   #if !defined(sequent) && !defined(NeXT)
  233. ! #include <memory.h>
  234.   #else
  235.   #define memcpy(s1, s2, n) strncpy(s1, s2, n) 
  236. --- 49,53 ----
  237.   
  238.   #if !defined(sequent) && !defined(NeXT)
  239. ! /* #include <memory.h> */
  240.   #else
  241.   #define memcpy(s1, s2, n) strncpy(s1, s2, n) 
  242. diff -2rcN binutils-1.8.x/ld.c binutils-1.8.x-amiga/ld.c
  243. *** binutils-1.8.x/ld.c    Sat Jun 18 00:10:10 1994
  244. --- binutils-1.8.x-amiga/ld.c    Sat Jul 30 13:26:33 1994
  245. ***************
  246. *** 17,23 ****
  247.   
  248.   /* Written by Richard Stallman with some help from Eric Albert.
  249. !    Set, indirect, and warning symbol features added by Randy Smith.  */
  250.   
  251.   #include <ar.h>
  252.   #include <stdio.h>
  253.   #include <sys/types.h>
  254. --- 17,38 ----
  255.   
  256.   /* Written by Richard Stallman with some help from Eric Albert.
  257. !    Set, indirect, and warning symbol features added by Randy Smith.
  258. !    Support for generation of Amiga load files added by Markus Wild.
  259. !    Flavor extension by Fred Fish
  260. !    Modified for AmigaDOS cross-linker by Philippe Brand
  261. !    Bug fixes by Matthias Fleischer
  262. !    Additional work by Gunther Nikl */
  263.   
  264. + #ifdef amigados
  265. + #ifndef STANDARD_SEARCH_DIRS
  266. + #define STANDARD_SEARCH_DIRS "gnu:lib","gnu:os-lib"
  267. + #endif
  268. + #endif
  269. + #if defined(amigados) && defined(CROSS_LINKER)
  270. + #include </usr/local/amigados/include/ar.h>
  271. + #else
  272.   #include <ar.h>
  273. + #endif
  274.   #include <stdio.h>
  275.   #include <sys/types.h>
  276. ***************
  277. *** 31,34 ****
  278. --- 46,51 ----
  279.   #include <fcntl.h>
  280.   #endif
  281. + /* JPB, 7 Jun 1992: MAXNAMLEN required for long name hack. */
  282. + #include <dirent.h>
  283.   
  284.   #if !defined(A_OUT) && !defined(MACH_O)
  285. ***************
  286. *** 40,46 ****
  287. --- 57,98 ----
  288.   #include "a.out.encap.h"
  289.   #else
  290. + #if defined(amigados) && defined(CROSS_LINKER)
  291. + # include </usr/local/amigados/include/a.out.h>
  292. + #else
  293.   #include <a.out.h>
  294.   #endif
  295.   #endif
  296. + #endif
  297. + #ifdef MCH_AMIGA
  298. + #define HUNK_INSTEAD_OF_A_OUT
  299. + int number_of_code_hunk,
  300. +     code_mem_type,
  301. +     number_of_data_hunk,
  302. +     data_mem_type,
  303. +     number_of_bss_hunk,
  304. +     bss_mem_type,
  305. +     number_of_debug_hunk,
  306. +     current_hunk = 0,
  307. +     offset_of_debug_hunk,
  308. +     amiga_symbols_only,
  309. +     long_data_hunk = 1,
  310. +     databss_together = 0,
  311. +     numdatadata_relocs = 0,
  312. +     output_datadata_relocs = 0,
  313. +     datadata_relocs_offset = 0;
  314. + #define LONGSIZE(l) ((((l) + 3) & ~3) >> 2)
  315. + /* this is the private format of the debug-hunk: */
  316. +    struct debug_hunk {
  317. +      unsigned long  id;  /* Filesystem-imposed: HUNK_DEBUG (0x3f1) */
  318. +      unsigned long  len; /* "" : length in longs -> LONGSIZE(real_lenght) */
  319. +      /* the following part is somehow a truncated exec-struct: */
  320. +      unsigned long  magic; /* should be ZMAGIC (just for fun:-)), to be recognised
  321. +                 * by the other tools as this special frame */
  322. +      unsigned long  syms;  /* size of symbol-table */
  323. +      unsigned long  strs;  /* size of string table */
  324. +      /* here follows the actual data */
  325. +    } dh;
  326. + #endif
  327.   
  328.   #ifdef MACH_O
  329. ***************
  330. *** 105,109 ****
  331.   
  332.   char *progname;
  333.   /* System dependencies */
  334.   
  335. --- 157,161 ----
  336.   
  337.   char *progname;
  338.   /* System dependencies */
  339.   
  340. ***************
  341. *** 191,194 ****
  342. --- 243,262 ----
  343.   #endif /* Sun.  */
  344.   
  345. + #ifdef amigados
  346. + /* same trick as with sun[23] */
  347. + /* Set the machine type according to the machine type of the .o files.
  348. +    If they are all sun2 (68010), then the type of the executable is sun2.
  349. +    If any is sun3 (68020), then the type of the executable is sun3.
  350. +    This is consistent with the Sun loader and more useful than having
  351. +    it depend on which machine you are on when you run ld.  */
  352. + static int amiga_machtype = MID_SUN010;
  353. + #define INITIALIZE_HEADER outheader.a_machtype = amiga_machtype
  354. + #define READ_HEADER_HOOK(machtype) \
  355. +   if (machtype == MID_SUN020)        \
  356. +     {                     \
  357. +       amiga_machtype = MID_SUN020;   \
  358. +     }
  359. + #endif
  360.   #ifdef ALTOS
  361.   #define INITIALIZE_HEADER N_SET_MACHTYPE (outheader, M_68020)
  362. ***************
  363. *** 230,233 ****
  364. --- 298,305 ----
  365.   #define SEEK_CUR 1
  366.   #endif
  367. + /* Phil.B: 1-Apr-94: same trick for SEEK_END */
  368. + #ifndef SEEK_END
  369. + #define SEEK_END L_XTND
  370. + #endif
  371.   
  372.   /*
  373. ***************
  374. *** 369,372 ****
  375. --- 441,445 ----
  376.   #undef RELOC_ADD_EXTRA
  377.   #define RELOC_PCREL_P(r)        ((r)->r_pcrel)
  378. + #define RELOC_BASEREL_P(r)        ((r)->r_baserel)
  379.   #define RELOC_VALUE_RIGHTSHIFT(r)    0
  380.   #define RELOC_TARGET_SIZE(r)        ((r)->r_length)
  381. ***************
  382. *** 385,389 ****
  383.   #endif
  384.   
  385.   /* Special global symbol types understood by GNU LD.  */
  386.   
  387. --- 458,462 ----
  388.   #endif
  389.   
  390.   /* Special global symbol types understood by GNU LD.  */
  391.   
  392. ***************
  393. *** 532,536 ****
  394.   
  395.   #endif /* not __GNU_STAB__ */
  396.   /* Symbol table */
  397.   
  398. --- 605,609 ----
  399.   
  400.   #endif /* not __GNU_STAB__ */
  401.   /* Symbol table */
  402.   
  403. ***************
  404. *** 685,689 ****
  405.   symbol *etext_symbol_alt;
  406.   symbol *end_symbol_alt;
  407.   /* Kinds of files potentially understood by the linker. */
  408.   
  409. --- 758,770 ----
  410.   symbol *etext_symbol_alt;
  411.   symbol *end_symbol_alt;
  412. ! #ifdef amigados
  413. ! symbol *sdata_symbol;    /* the symbol __sdata */
  414. ! symbol *text_size_symbol;
  415. ! symbol *data_size_symbol;
  416. ! symbol *bss_size_symbol;
  417. ! symbol *datadata_reloc_symbol = 0;
  418. ! #endif
  419.   /* Kinds of files potentially understood by the linker. */
  420.   
  421. ***************
  422. *** 821,825 ****
  423.   /* Length of that vector.  */
  424.   int number_of_files;
  425.   /* When loading the text and data, we can avoid doing a close
  426.      and another open between members of the same library.
  427. --- 902,906 ----
  428.   /* Length of that vector.  */
  429.   int number_of_files;
  430.   /* When loading the text and data, we can avoid doing a close
  431.      and another open between members of the same library.
  432. ***************
  433. *** 868,874 ****
  434. --- 949,960 ----
  435.   #endif
  436.   
  437. + #if 0
  438.   /* Descriptor for writing that file with `mywrite'.  */
  439.   
  440.   int outdesc;
  441. + #endif
  442. + /* use outstream instead of outdesc thru the whole file, it's MUCH faster.. */
  443. + FILE *outstream = (FILE *) 0;
  444.   
  445.   /* The following are computed by `digest_symbols'.  */
  446. ***************
  447. *** 910,913 ****
  448. --- 996,1003 ----
  449.      written. */
  450.   unsigned long *set_vectors;
  451. + #ifdef HUNK_INSTEAD_OF_A_OUT
  452. + /* which vector entry has to be relocated? */
  453. + unsigned char *rel_vectors;
  454. + #endif
  455.   
  456.   /* Amount of cleared space to leave at the end of the text segment.  */
  457. ***************
  458. *** 930,934 ****
  459.     int library_member_offset;
  460.   };
  461.   /* Record most of the command options.  */
  462.   
  463. --- 1020,1024 ----
  464.     int library_member_offset;
  465.   };
  466.   /* Record most of the command options.  */
  467.   
  468. ***************
  469. *** 994,997 ****
  470. --- 1084,1091 ----
  471.   int n_search_dirs;
  472.   
  473. + /* Vector of flavors to search for. */
  474. + char **flavors;
  475. + int n_flavors;
  476.   /* Non zero means to create the output executable.
  477.      Cleared by nonfatal errors.  */
  478. ***************
  479. *** 1008,1017 ****
  480. --- 1102,1117 ----
  481.   int cl_refs_allocated;
  482.   
  483. + /* JPB, 7 Jun 1992: Global variable needed for long name hack. */
  484. + static int ar_hdr_size;
  485.   #ifndef bcopy
  486.   void bcopy (), bzero ();
  487.   #endif
  488. + #ifndef __STDC__
  489.   char *malloc (), *realloc ();
  490.   void free ();
  491. + #endif
  492.   
  493. + char *getenv ();
  494.   char *xmalloc ();
  495.   char *xrealloc ();
  496. ***************
  497. *** 1035,1038 ****
  498. --- 1135,1153 ----
  499.   void write_header ();
  500.   void write_text ();
  501. + #ifdef HUNK_INSTEAD_OF_A_OUT
  502. + void write_datadata_relocs ();
  503. + void write_hunk_header ();
  504. + void conditionally_rewrite_headers ();
  505. + void write_bss ();
  506. + void init_reloc_hunk ();
  507. + void add_to_reloc_hunk ();
  508. + void write_reloc_hunk ();
  509. + void init_symbol_hunks ();
  510. + void add_to_symbol_hunk ();
  511. + void write_symbol_hunk ();
  512. + void look_for_symbols ();
  513. + void look_for_file_symbols ();
  514. + void relocate_set_vectors ();
  515. + #endif
  516.   void read_file_relocation ();
  517.   void write_data ();
  518. ***************
  519. *** 1046,1050 ****
  520.   char *get_file_name ();
  521.   symbol *getsym (), *getsym_soft ();
  522.   int
  523.   main (argc, argv)
  524. --- 1161,1166 ----
  525.   char *get_file_name ();
  526.   symbol *getsym (), *getsym_soft ();
  527. ! int compare_longs (), compare_strings ();
  528.   int
  529.   main (argc, argv)
  530. ***************
  531. *** 1052,1059 ****
  532.        int argc;
  533.   {
  534.     page_size = getpagesize ();
  535.     progname = argv[0];
  536.   
  537. ! #ifdef RLIMIT_STACK
  538.     /* Avoid dumping core on large .o files.  */
  539.     {
  540. --- 1168,1186 ----
  541.        int argc;
  542.   {
  543. + /* Phil.B 09-Jul-94: use 4KB as page size in order to be compatible with Gigamem
  544. +    although getpagesize() is present in ixemul.library, we want to compile
  545. +    without it */
  546. + #ifdef amigados
  547. +   page_size = 4096;
  548. + #else
  549.     page_size = getpagesize ();
  550. + #endif
  551.     progname = argv[0];
  552.   
  553. ! /* Phil.B 09-Jul-94: amigados doesn't have stack growing so this is not
  554. !    necessary and more than that disable ld to be compiled using libnix
  555. !    BTW as for now those functions returns 0 in  ixemul.library.
  556. !    That's emulation! ;-) */
  557. ! #if defined(RLIMIT_STACK) && !defined(amigados)
  558.     /* Avoid dumping core on large .o files.  */
  559.     {
  560. ***************
  561. *** 1091,1094 ****
  562. --- 1218,1224 ----
  563.     force_executable = 0;
  564.     set_element_prefixes = 0;
  565. + #ifdef HUNK_INSTEAD_OF_A_OUT
  566. +   amiga_symbols_only = 1;
  567. + #endif
  568.   
  569.     /* Initialize the cumulative counts of symbols.  */
  570. ***************
  571. *** 1149,1157 ****
  572.     exit (!make_executable);
  573.   }
  574.   void add_cmdline_ref ();
  575.   
  576.   static struct option longopts[] =
  577.   {
  578.     {"d", 0, 0, 'd'},
  579.     {"dc", 0, 0, 'd'},        /* For Sun compatibility. */
  580. --- 1279,1317 ----
  581.     exit (!make_executable);
  582.   }
  583. ! #ifdef amigados
  584. ! /* support hunk loading to a chip or fast memory */
  585. ! void set_mem_type(char *argstr, int memtype)
  586. ! {
  587. !    static char memstr[]="cdb";
  588. !    if (!argstr)
  589. !      argstr=memstr;
  590. !    if (strchr(argstr,'c')||strchr(argstr,'t'))
  591. !      code_mem_type=memtype;
  592. !    if (strchr(argstr,'d'))
  593. !      data_mem_type=memtype;
  594. !    if (strchr(argstr,'b'))
  595. !      bss_mem_type=memtype;
  596. ! }
  597. ! #endif
  598.   void add_cmdline_ref ();
  599.   
  600.   static struct option longopts[] =
  601.   {
  602. + #ifdef HUNK_INSTEAD_OF_A_OUT
  603. +   {"amiga-debug-hunk", 0, 0, 'a'},
  604. +   {"databss-together", 0, 0, 'b'},
  605. +   {"datadata-reloc", 0, 0, 'c'},
  606. +   {"msmall-code", 0, 0, 129},        /* ignore.. */
  607. +   {"flavor", 1, 0, 'f'},
  608. +   {"chip",2, 0, 'g'},
  609. +   {"fast",2, 0, 'h'},
  610. +   {"shortdata", 0, 0, 'm'},
  611. + #endif
  612.     {"d", 0, 0, 'd'},
  613.     {"dc", 0, 0, 'd'},        /* For Sun compatibility. */
  614. ***************
  615. *** 1208,1211 ****
  616. --- 1368,1384 ----
  617.        Also process most options completely.  */
  618.   
  619. + #ifdef amigados
  620. +   /* Phil.B: 27-Feb-94 default is to strip all symbols if LDSTRIP is set */
  621. +   if (getenv("LDSTRIP"))
  622. +     strip_symbols = STRIP_ALL;
  623. +   /* G.Nikl: 10-Jun-94 if LDSHORTDATA is found a "short" data hunk will be
  624. +      created. bss will be allocated via the hunk header. default is to dump
  625. +      the bss part in the data area as zeros */
  626. +   if (getenv("LDSHORTDATA"))
  627. +     long_data_hunk = 0;
  628. + #endif /* amigados */
  629.     while ((optc = getopt_long_only (argc, argv, SHORTOPTS, longopts, &longind))
  630.        != EOF)
  631. ***************
  632. *** 1225,1228 ****
  633. --- 1398,1415 ----
  634.         break;
  635.   
  636. + #ifdef HUNK_INSTEAD_OF_A_OUT
  637. +     case 'a':
  638. +       amiga_symbols_only = 0;
  639. +       break;
  640. +     case 'b':
  641. +       databss_together = 1;
  642. +       break;
  643. +     case 'c':
  644. +       output_datadata_relocs = 1;
  645. +       break;
  646. + #endif
  647.       case 'd':
  648.         force_common_definition = 1;
  649. ***************
  650. *** 1237,1244 ****
  651. --- 1424,1450 ----
  652.         break;
  653.   
  654. +     case 'f':
  655. +       n_flavors++;
  656. +       flavors = (char **) xrealloc (flavors, n_flavors * sizeof (char *));
  657. +       flavors[n_flavors - 1] = optarg;
  658. +       break;
  659. + #ifdef HUNK_INSTEAD_OF_A_OUT
  660. +     case 'g':
  661. +       set_mem_type(optarg,1<<30);
  662. +       break;
  663. +     case 'h':
  664. +       set_mem_type(optarg,2<<30);
  665. +       break;
  666. + #endif
  667.       case 'l':
  668.         number_of_files++;
  669.         break;
  670.   
  671. +     case 'm':
  672. +       long_data_hunk = 0;
  673. +       break;
  674.       case 'n':
  675.         if (output_style && output_style != OUTPUT_READONLY_TEXT)
  676. ***************
  677. *** 1364,1367 ****
  678. --- 1570,1583 ----
  679.       }
  680.   
  681. +   if (n_flavors > 1)
  682. +     {
  683. +       register int i;
  684. +       if (trace_files)
  685. +         for (i=0; i<n_flavors; i++)
  686. +       fprintf (stderr, "Flavor #%d : %s\n", i, flavors[i]);
  687. +       qsort (flavors, n_flavors, sizeof (char *), compare_strings);
  688. +     }
  689.     if (!number_of_files)
  690.       usage ("no input files", 0);
  691. ***************
  692. *** 1434,1438 ****
  693.       }
  694.   }
  695.   
  696.   void
  697. --- 1650,1654 ----
  698.       }
  699.   }
  700.   
  701.   void
  702. ***************
  703. *** 1479,1483 ****
  704.     return 0;
  705.   }
  706.   /* Convenient functions for operating on one or all files being
  707.      loaded.  */
  708. --- 1695,1699 ----
  709.     return 0;
  710.   }
  711.   /* Convenient functions for operating on one or all files being
  712.      loaded.  */
  713. ***************
  714. *** 1603,1608 ****
  715.         for (i = 0; i < n_search_dirs; i++)
  716.       {
  717. !       register char *string
  718. !         = concat (search_dirs[i], "/", entry->filename);
  719.         desc = open (string, O_RDONLY, 0);
  720.         if (desc > 0)
  721. --- 1819,1835 ----
  722.         for (i = 0; i < n_search_dirs; i++)
  723.       {
  724. !       register char *string;
  725. !       string = search_dirs[i];
  726. !       if (n_flavors > 0)
  727. !         {
  728. !           int count;
  729. !           for (count = 0; count < n_flavors; count++)
  730. !         {
  731. !           string = concat (string, "/", flavors[count]);
  732. !         }
  733. !         }
  734. !       string = concat (string, "/", entry->filename);
  735. !       if (trace_files) fprintf (stderr, "Look for %s\n", string);
  736.         desc = open (string, O_RDONLY, 0);
  737.         if (desc > 0)
  738. ***************
  739. *** 1614,1617 ****
  740. --- 1841,1879 ----
  741.         free (string);
  742.       }
  743. +       /* Phil.B 30-Jul-94 if we couldn't find file using serch_dirs
  744. +      then we try removing trailing path one by one */
  745. +       if ((desc <= 0) && (n_flavors > 0))
  746. +     {
  747. +           if (trace_files) fprintf (stderr, "Climbing into flavors\n");
  748. +           for (i = 0; i < n_search_dirs; i++)
  749. +         {
  750. +           register int j;
  751. +           register char *string;
  752. +           for (j = n_flavors; j >= 0; j--)
  753. +                 {
  754. +                   int count;
  755. +               string = search_dirs[i];
  756. +           /* Phil.B 29-Jul-94 Special condition is made so that
  757. +              if j = 0 we don't copy flavor because we want to test
  758. +              search path without any flavor added. */
  759. +               for (count = 1; count <= j ; count++)
  760. +             {
  761. +               string = concat (string, "/", flavors[count-1]);
  762. +             }
  763. +               string = concat (string, "/", entry->filename);
  764. +               if (trace_files) fprintf (stderr, "Look for %s\n", string);
  765. +               desc = open (string, O_RDONLY, 0);
  766. +               if (desc > 0)
  767. +                 {
  768. +                   entry->filename = string;
  769. +                   entry->search_dirs_flag = 0;
  770. +                   break;
  771. +                 }
  772. +               free (string);
  773. +                 }
  774. +           if (desc > 0) break;
  775. +         }
  776. +         }
  777.       }
  778.     else
  779. ***************
  780. *** 1679,1683 ****
  781.     return result;
  782.   }
  783.   /* Medium-level input routines for rel files.  */
  784.   
  785. --- 1941,1945 ----
  786.     return result;
  787.   }
  788.   /* Medium-level input routines for rel files.  */
  789.   
  790. ***************
  791. *** 2045,2049 ****
  792.       fatal_with_file ("premature end of file in strings of ", entry);
  793.   }
  794.   /* Read in the symbols of all input files.  */
  795.   
  796. --- 2307,2311 ----
  797.       fatal_with_file ("premature end of file in strings of ", entry);
  798.   }
  799.   /* Read in the symbols of all input files.  */
  800.   
  801. ***************
  802. *** 2098,2102 ****
  803.     file_close ();
  804.   }
  805.   /* Enter the external symbol defs and refs of ENTRY in the hash table.  */
  806.   
  807. --- 2360,2364 ----
  808.     file_close ();
  809.   }
  810.   /* Enter the external symbol defs and refs of ENTRY in the hash table.  */
  811.   
  812. ***************
  813. *** 2121,2124 ****
  814. --- 2383,2396 ----
  815.       {
  816.         set_symbol_count++;
  817. + /* Matthias Fleischer 25-Apr-94: fix bug in ld that prevents
  818. +    symboltables for objects in the data hunk from working. */
  819. + #ifdef HUNK_INSTEAD_OF_A_OUT
  820. +         /* Count pointers in the symbol table, too */
  821. +       if ((p->n_type&~N_EXT)==N_SETD||
  822. +               (p->n_type&~N_EXT)==N_SETB)
  823. +         numdatadata_relocs++;
  824. + #endif
  825.         if (output_style != OUTPUT_RELOCATABLE)
  826.           enter_global_ref (p, p->n_un.n_strx + entry->strings, entry);
  827. ***************
  828. *** 2376,2380 ****
  829.   }
  830.   
  831.   /* Searching libraries */
  832.   
  833. --- 2648,2652 ----
  834.   }
  835.   
  836.   /* Searching libraries */
  837.   
  838. ***************
  839. *** 2453,2458 ****
  840. --- 2725,2755 ----
  841.          namelen++);
  842.   
  843. + /* JPB, 7 Jun 1992: Support for long file names. Set the global variable
  844. +                     ar_hdr_size to the real length of the header.
  845. +                     The code for extracting the long name is pretty much stolen
  846. +                     from the BSD ar (archive.c, version 5.7).
  847. +                     This is a *really* ugly hack!
  848. + */
  849. + #if 1
  850. +   ar_hdr_size = sizeof(struct ar_hdr);
  851. +   if (!bcmp(hdr1.ar_name,AR_EFMT1,sizeof(AR_EFMT1) -1))
  852. +   {
  853. +     namelen = atoi(hdr1.ar_name + sizeof(AR_EFMT1) -1);
  854. +     if (namelen <= 0 || namelen > MAXNAMLEN)
  855. +       fatal_with_file("malformatted long name of archive member in ",library_entry);
  856. +     ar_hdr_size += namelen;
  857. +     name = (char *) xmalloc (namelen+1);
  858. +     if (read(desc,name,namelen) != namelen)
  859. +       fatal_with_file("malformatted long name of archive member in ",library_entry);
  860. +   }
  861. +   else
  862. +   {
  863. +     name = (char *) xmalloc (namelen+1);
  864. +     strncpy (name, hdr1.ar_name, namelen);
  865. +   }
  866. + #else
  867.     name = (char *) xmalloc (namelen+1);
  868.     strncpy (name, hdr1.ar_name, namelen);
  869. + #endif
  870.     name[namelen] = 0;
  871.   
  872. ***************
  873. *** 2462,2466 ****
  874. --- 2759,2767 ----
  875.     subentry->strings = 0;
  876.     subentry->subfiles = 0;
  877. + #if 1
  878. +   subentry->starting_offset = subfile_offset + ar_hdr_size;
  879. + #else
  880.     subentry->starting_offset = subfile_offset + sizeof hdr1;
  881. + #endif
  882.     subentry->superfile = library_entry;
  883.     subentry->library_flag = 0;
  884. ***************
  885. *** 2474,2478 ****
  886.     return subentry;
  887.   }
  888.   int subfile_wanted_p ();
  889.   
  890. --- 2775,2779 ----
  891.     return subentry;
  892.   }
  893.   int subfile_wanted_p ();
  894.   
  895. ***************
  896. *** 2623,2627 ****
  897.     free (symdef_data);
  898.   }
  899.   
  900.   /* Handle a subentry for a file with no __.SYMDEF. */
  901. --- 2924,2928 ----
  902.     free (symdef_data);
  903.   }
  904.   
  905.   /* Handle a subentry for a file with no __.SYMDEF. */
  906. ***************
  907. *** 2676,2684 ****
  908.   
  909.         process_subentry (desc, subentry, entry, &prev);
  910.         this_subfile_offset += member_length + sizeof (struct ar_hdr);
  911.         if (this_subfile_offset & 1) this_subfile_offset++;
  912.       }
  913.   }
  914.   /* ENTRY is an entry for a library member.
  915.      Its symbols have been read into core, but not entered.
  916. --- 2977,2993 ----
  917.   
  918.         process_subentry (desc, subentry, entry, &prev);
  919. + #if 1
  920. + /* JPB, 7 Jun 1992: Can't count on sizeof(ar_hdr) to be the size of the entire
  921. +                     header: Long names extends the header. This is a *really*
  922. +                     ugly hack, using a global variable! */
  923. +       this_subfile_offset += member_length + ar_hdr_size;
  924. + #else
  925.         this_subfile_offset += member_length + sizeof (struct ar_hdr);
  926. + #endif
  927.         if (this_subfile_offset & 1) this_subfile_offset++;
  928.       }
  929.   }
  930.   /* ENTRY is an entry for a library member.
  931.      Its symbols have been read into core, but not entered.
  932. ***************
  933. *** 2778,2782 ****
  934.     return 0;
  935.   }
  936.   void consider_file_section_lengths (), relocate_file_addresses ();
  937.   
  938. --- 3087,3091 ----
  939.     return 0;
  940.   }
  941.   void consider_file_section_lengths (), relocate_file_addresses ();
  942.   
  943. ***************
  944. *** 2801,2805 ****
  945. --- 3110,3118 ----
  946.     initialize_text_start ();
  947.   
  948. + #ifdef HUNK_INSTEAD_OF_A_OUT
  949. +   text_size = 0;
  950. + #else
  951.     text_size = text_header_size;
  952. + #endif
  953.   
  954.     /* Compute total size of sections */
  955. ***************
  956. *** 2810,2813 ****
  957. --- 3123,3127 ----
  958.        Include the padding in the text segment size.  */
  959.   
  960. + #ifndef HUNK_INSTEAD_OF_A_OUT
  961.     if (output_style == OUTPUT_READONLY_TEXT || output_style == OUTPUT_DEMAND_PAGED)
  962.       {
  963. ***************
  964. *** 2815,2818 ****
  965. --- 3129,3145 ----
  966.         text_size += text_pad;
  967.       }
  968. + #endif
  969. + #ifdef HUNK_INSTEAD_OF_A_OUT
  970. +   /* they go into text if they are required */
  971. +   if (output_datadata_relocs && numdatadata_relocs)
  972. +     {
  973. +       if (datadata_reloc_symbol)
  974. +         datadata_reloc_symbol->value = text_size;
  975. +       
  976. +       /* 1 long for the size, then the vector */
  977. +       text_size += (1 + numdatadata_relocs) * 4;
  978. +     }
  979. + #endif
  980.   
  981.     /* Now that the text_size is known, initialize the data start address;
  982. ***************
  983. *** 2821,2824 ****
  984. --- 3148,3157 ----
  985.     initialize_data_start ();
  986.   
  987. + #ifdef HUNK_INSTEAD_OF_A_OUT
  988. +   data_pad = 0;
  989. + #endif
  990. + #ifndef HUNK_INSTEAD_OF_A_OUT
  991.     /* Make sure bss starts out aligned as much as anyone can want.  */
  992.     {
  993. ***************
  994. *** 2828,2831 ****
  995. --- 3161,3165 ----
  996.       data_size = new_data_size;
  997.     }
  998. + #endif
  999.   
  1000.     /* Set up the set element vector */
  1001. ***************
  1002. *** 2837,2845 ****
  1003. --- 3171,3189 ----
  1004.        vector, plus a word for each symbol for a zero at the end of
  1005.        the vector (for incremental linking).  */
  1006. + #if 0
  1007. +       /* I think this is the other way round !? ### mw */
  1008.         set_sect_size
  1009.       = (2 * set_symbol_count + set_vector_count) * sizeof (unsigned long);
  1010. + #else
  1011. +       set_sect_size
  1012. +     = (2 * set_vector_count + set_symbol_count) * sizeof (unsigned long);
  1013. + #endif
  1014.         set_sect_start = data_start + data_size;
  1015.         data_size += set_sect_size;
  1016.         set_vectors = (unsigned long *) xmalloc (set_sect_size);
  1017. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1018. +       rel_vectors = (unsigned char *) xmalloc (set_sect_size/sizeof(unsigned long));
  1019. + #endif
  1020.         setv_fill_count = 0;
  1021.       }
  1022. ***************
  1023. *** 2889,2893 ****
  1024. --- 3233,3253 ----
  1025.                 multiple_def_count++;
  1026.               }
  1027. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1028. +           /* don't relocate absolute symbols in sets */
  1029. +           rel_vectors[setv_fill_count] = ( ((type & ~N_EXT) != N_SETA) );
  1030. +           /* Matthias Fleischer 25-Apr-94: fix bug in ld that prevents
  1031. +              symboltables for objects in the data hunk from working. */
  1032. +           /* This is some kind of hack, but doing this cleaner would be 
  1033. +              much more complicated */
  1034. +           set_vectors[setv_fill_count++] = p->n_value
  1035. +             +( (type & ~N_EXT) == N_SETD ? text_size : 0 )
  1036. +             +( (type & ~N_EXT) == N_SETB ? data_size : 0 );
  1037. + #else          
  1038.             set_vectors[setv_fill_count++] = p->n_value;
  1039. + #endif
  1040.           }
  1041.             else if ((type & N_EXT) && type != (N_UNDF | N_EXT))
  1042. ***************
  1043. *** 2932,2936 ****
  1044. --- 3292,3302 ----
  1045.                     - data_size - data_start);
  1046.   
  1047. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1048. +           sp->value = bss_size;
  1049. +           if (databss_together)
  1050. +             sp->value += data_start + data_size;
  1051. + #else
  1052.             sp->value = data_start + data_size + bss_size;
  1053. + #endif
  1054.             sp->defined = N_BSS | N_EXT;
  1055.             bss_size += com;
  1056. ***************
  1057. *** 2952,2955 ****
  1058. --- 3318,3322 ----
  1059.           = (sp->value - set_sect_start) / sizeof (unsigned long);
  1060.             unsigned long i, tmp;
  1061. +           unsigned char tmp2;
  1062.   
  1063.             set_vectors[length_word_index]
  1064. ***************
  1065. *** 2965,2968 ****
  1066. --- 3332,3342 ----
  1067.               = set_vectors[setv_fill_count - i];
  1068.             set_vectors[setv_fill_count - i] = tmp;
  1069. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1070. +           /* reverse relocation vector too! */
  1071. +           tmp2 = rel_vectors[length_word_index + i];
  1072. +           rel_vectors[length_word_index + i]
  1073. +             = rel_vectors[setv_fill_count - i];
  1074. +           rel_vectors[setv_fill_count - i] = tmp2;
  1075. + #endif
  1076.           }
  1077.   
  1078. ***************
  1079. *** 2995,2998 ****
  1080. --- 3369,3385 ----
  1081.     }
  1082.   
  1083. + #ifdef amigados
  1084. +   {
  1085. +     if (sdata_symbol)
  1086. +       sdata_symbol->value = data_start;
  1087. +     if (text_size_symbol)
  1088. +       text_size_symbol->value = text_size;
  1089. +     if (data_size_symbol)
  1090. +       data_size_symbol->value = data_size;
  1091. +     if (bss_size_symbol)
  1092. +       bss_size_symbol->value  = bss_size;
  1093. +   }
  1094. + #endif
  1095.     {
  1096.       int edata_value = data_start + data_size;
  1097. ***************
  1098. *** 3014,3020 ****
  1099. --- 3401,3409 ----
  1100.         data_pad_additional = specified_data_size - data_size;
  1101.   
  1102. + #ifndef HUNK_INSTEAD_OF_A_OUT
  1103.       if (output_style == OUTPUT_DEMAND_PAGED)
  1104.         data_pad_additional =
  1105.       ((data_pad_additional + data_size + page_size - 1) & (- page_size)) - data_size;
  1106. + #endif
  1107.   
  1108.       bss_size -= data_pad_additional;
  1109. ***************
  1110. *** 3025,3030 ****
  1111.       data_pad += data_pad_additional;
  1112.     }
  1113.   }
  1114.   /* Accumulate the section sizes of input file ENTRY
  1115.      into the section sizes of the output file.  */
  1116. --- 3414,3451 ----
  1117.       data_pad += data_pad_additional;
  1118.     }
  1119. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1120. +   /* if there is some code, assign it next hunk_number */
  1121. +   if (text_size)
  1122. +      number_of_code_hunk = current_hunk++;
  1123. +   else
  1124. +      number_of_code_hunk = -1;
  1125. +   if (data_size)
  1126. +      number_of_data_hunk = current_hunk++;
  1127. +   else
  1128. +      number_of_data_hunk = -1;
  1129. +   if (bss_size)
  1130. +      number_of_bss_hunk  = current_hunk++;
  1131. +   else
  1132. +      number_of_bss_hunk  = -1;
  1133. +   if (databss_together)
  1134. +     {
  1135. +       if (data_size && bss_size)
  1136. +     {
  1137. +       current_hunk --;
  1138. +       number_of_bss_hunk = number_of_data_hunk;
  1139. +     }
  1140. +     }
  1141. +   if (strip_symbols != STRIP_ALL && !amiga_symbols_only)
  1142. +      number_of_debug_hunk = current_hunk++;
  1143. +   else
  1144. +      number_of_debug_hunk = -1;
  1145. + #endif
  1146.   }
  1147.   /* Accumulate the section sizes of input file ENTRY
  1148.      into the section sizes of the output file.  */
  1149. ***************
  1150. *** 3047,3050 ****
  1151. --- 3468,3495 ----
  1152.     text_reloc_size += entry->text_reloc_size;
  1153.     data_reloc_size += entry->data_reloc_size;
  1154. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1155. +   if (! output_datadata_relocs)
  1156. +     return;
  1157. +   /* have to guess at how many datadata-relocs we might have. This number
  1158. +      is larger than the real thing, because I have to include the references
  1159. +      to UNDF symbols as well. */
  1160. +   {
  1161. +     struct relocation_info *r, *re, *reloc;
  1162. +     int desc = file_open (entry);
  1163. +     reloc = (struct relocation_info *) alloca (entry->data_reloc_size);
  1164. +     lseek (desc, entry->starting_offset + entry->data_reloc_offset, L_SET);
  1165. +     if (entry->data_reloc_size != read (desc, reloc, entry->data_reloc_size))
  1166. +       fatal_with_file ("premature eof in data relocation of ", entry);
  1167. +     
  1168. +     for (r = reloc, re = reloc + entry->data_reloc_size/sizeof(*re); r < re; r++)
  1169. +       if (RELOC_EXTERN_P (r) || ((RELOC_TYPE (r) & N_TYPE) != N_TEXT))
  1170. +     numdatadata_relocs ++;
  1171. +     file_close ();
  1172. +   }
  1173. + #endif
  1174.   }
  1175.   
  1176. ***************
  1177. *** 3063,3067 ****
  1178.        been, we would get the wrong results here.  */
  1179.     entry->data_start_address += data_start;
  1180. !   entry->bss_start_address += data_start + data_size;
  1181.   
  1182.     {
  1183. --- 3508,3517 ----
  1184.        been, we would get the wrong results here.  */
  1185.     entry->data_start_address += data_start;
  1186. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1187. !   if (databss_together)
  1188. ! #endif
  1189. !     entry->bss_start_address += data_start + data_size;
  1190.   
  1191.     {
  1192. ***************
  1193. *** 3081,3086 ****
  1194.           p->n_value += entry->text_start_address - entry->orig_text_address;
  1195.           break;
  1196. -       case N_DATA:
  1197.         case N_SETV:
  1198.         case N_SETD:
  1199.           /* Data segment symbol.  Subtract the address of the
  1200. --- 3531,3536 ----
  1201.           p->n_value += entry->text_start_address - entry->orig_text_address;
  1202.           break;
  1203.         case N_SETV:
  1204. +       case N_DATA:
  1205.         case N_SETD:
  1206.           /* Data segment symbol.  Subtract the address of the
  1207. ***************
  1208. *** 3099,3103 ****
  1209.     }
  1210.   }
  1211.   void describe_file_sections (), list_file_locals ();
  1212.   
  1213. --- 3549,3553 ----
  1214.     }
  1215.   }
  1216.   void describe_file_sections (), list_file_locals ();
  1217.   
  1218. ***************
  1219. *** 3175,3179 ****
  1220.   }
  1221.   
  1222.   /* Static vars for do_warnings and subroutines of it */
  1223.   int list_unresolved_refs;    /* List unresolved refs */
  1224. --- 3625,3629 ----
  1225.   }
  1226.   
  1227.   /* Static vars for do_warnings and subroutines of it */
  1228.   int list_unresolved_refs;    /* List unresolved refs */
  1229. ***************
  1230. *** 3193,3197 ****
  1231.   };
  1232.   
  1233. - void qsort ();
  1234.   /*
  1235.    * Helper routines for do_file_warnings.
  1236. --- 3643,3646 ----
  1237. ***************
  1238. *** 3673,3677 ****
  1239.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  1240.   }
  1241.   do_warnings (outfile)
  1242.        FILE *outfile;
  1243. --- 4122,4126 ----
  1244.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  1245.   }
  1246.   do_warnings (outfile)
  1247.        FILE *outfile;
  1248. ***************
  1249. *** 3692,3696 ****
  1250.       make_executable = 0;
  1251.   }
  1252.   #ifdef A_OUT
  1253.   
  1254. --- 4141,4145 ----
  1255.       make_executable = 0;
  1256.   }
  1257.   #ifdef A_OUT
  1258.   
  1259. ***************
  1260. *** 3713,3716 ****
  1261. --- 4162,4170 ----
  1262.     int magic;
  1263.   
  1264. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1265. +   text_start = 0;
  1266. +   return;
  1267. + #endif
  1268.     switch (output_style)
  1269.       {
  1270. ***************
  1271. *** 3771,3774 ****
  1272. --- 4225,4233 ----
  1273.   initialize_a_out_data_start ()
  1274.   {
  1275. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1276. +   data_start = 0;
  1277. +   return;
  1278. + #endif
  1279.     outheader.a_text = text_size;
  1280.   #ifdef sequent
  1281. ***************
  1282. *** 3924,3935 ****
  1283.   write_a_out_header ()
  1284.   {
  1285. !   lseek (outdesc, 0L, 0);
  1286.   
  1287.   #ifdef COFF_ENCAPSULATE
  1288.     if (need_coff_header)
  1289. !     mywrite (&coffheader, sizeof coffheader, 1, outdesc);
  1290.   #endif
  1291.   
  1292. !   mywrite (&outheader, sizeof (struct exec), 1, outdesc);
  1293.   
  1294.     /* Output whatever padding is required in the executable file
  1295. --- 4383,4394 ----
  1296.   write_a_out_header ()
  1297.   {
  1298. !   fseek (outstream, 0L, 0);
  1299.   
  1300.   #ifdef COFF_ENCAPSULATE
  1301.     if (need_coff_header)
  1302. !     mywrite (&coffheader, sizeof coffheader, 1, outstream);
  1303.   #endif
  1304.   
  1305. !   mywrite (&outheader, sizeof (struct exec), 1, outstream);
  1306.   
  1307.     /* Output whatever padding is required in the executable file
  1308. ***************
  1309. *** 3937,3946 ****
  1310.   
  1311.   #ifndef COFF_ENCAPSULATE
  1312. !   padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
  1313.   #endif
  1314.   }
  1315.   
  1316.   #endif
  1317.   #ifdef MACH_O
  1318.   
  1319. --- 4396,4405 ----
  1320.   
  1321.   #ifndef COFF_ENCAPSULATE
  1322. !   padfile (N_TXTOFF (outheader) - sizeof outheader, outstream);
  1323.   #endif
  1324.   }
  1325.   
  1326.   #endif
  1327.   #ifdef MACH_O
  1328.   
  1329. ***************
  1330. *** 4146,4150 ****
  1331.     thread_state state;
  1332.   
  1333. !   lseek (outdesc, 0L, 0);
  1334.   
  1335.   
  1336. --- 4605,4609 ----
  1337.     thread_state state;
  1338.   
  1339. !   fseek (outstream, 0L, 0);
  1340.   
  1341.   
  1342. ***************
  1343. *** 4252,4256 ****
  1344.         m_object.symseg = symseg;
  1345.   #endif
  1346. !       mywrite((char *) &m_object, 1, sizeof m_object, outdesc);
  1347.         break;
  1348.   
  1349. --- 4711,4715 ----
  1350.         m_object.symseg = symseg;
  1351.   #endif
  1352. !       mywrite((char *) &m_object, 1, sizeof m_object, outstream);
  1353.         break;
  1354.   
  1355. ***************
  1356. *** 4306,4310 ****
  1357.         m_exec.symseg = symseg;
  1358.   #endif
  1359. !       mywrite((char *) &m_exec, 1, sizeof m_exec, outdesc);
  1360.         break;
  1361.       }
  1362. --- 4765,4769 ----
  1363.         m_exec.symseg = symseg;
  1364.   #endif
  1365. !       mywrite((char *) &m_exec, 1, sizeof m_exec, outstream);
  1366.         break;
  1367.       }
  1368. ***************
  1369. *** 4387,4391 ****
  1370.   
  1371.   #endif
  1372.   /* The following functions are simple switches according to the
  1373.      output style.  */
  1374. --- 4846,4850 ----
  1375.   
  1376.   #endif
  1377.   /* The following functions are simple switches according to the
  1378.      output style.  */
  1379. ***************
  1380. *** 4485,4488 ****
  1381. --- 4944,4951 ----
  1382.   write_header ()
  1383.   {
  1384. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1385. +   conditionally_rewrite_headers ();
  1386. +   return;
  1387. + #else
  1388.   #ifdef A_OUT
  1389.     if (output_file_type == IS_A_OUT)
  1390. ***************
  1391. *** 4499,4505 ****
  1392.       }
  1393.   #endif
  1394.     fatal ("unknown output file type (enum file_type)", (char *) 0);
  1395.   }
  1396.   /* Write the output file */
  1397.   
  1398. --- 4962,4969 ----
  1399.       }
  1400.   #endif
  1401. + #endif
  1402.     fatal ("unknown output file type (enum file_type)", (char *) 0);
  1403.   }
  1404.   /* Write the output file */
  1405.   
  1406. ***************
  1407. *** 4520,4539 ****
  1408.     (void) unlink (output_filename);
  1409.     
  1410. !   outdesc = open (output_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  1411. !   if (outdesc < 0) perror_name (output_filename);
  1412.   
  1413. !   if (fstat (outdesc, &statbuf) < 0)
  1414.       perror_name (output_filename);
  1415.   
  1416.     filemode = statbuf.st_mode;
  1417.   
  1418.     chmod (output_filename, filemode & ~0111);
  1419.   
  1420.     /* Calculate the offsets of the various pieces of the output file.  */
  1421.     compute_section_offsets ();
  1422.   
  1423.     /* Output the text and data segments, relocating as we go.  */
  1424.     write_text ();
  1425.     write_data ();
  1426.   
  1427.     /* Output the merged relocation info, if requested with `-r'.  */
  1428. --- 4984,5049 ----
  1429.     (void) unlink (output_filename);
  1430.     
  1431. !   outstream = fopen (output_filename, "w");
  1432. !   if (outstream == 0) perror_name (output_filename);
  1433.   
  1434. ! #ifndef MCH_AMIGA
  1435. !   if (fstat (fileno (outstream), &statbuf) < 0)
  1436.       perror_name (output_filename);
  1437.   
  1438.     filemode = statbuf.st_mode;
  1439.   
  1440. +   /* this wouldn't work anyway, "file in use, error"... */
  1441.     chmod (output_filename, filemode & ~0111);
  1442. + #endif
  1443. +   /* on the Amiga, the following call DOES set the symbol offset, but
  1444. +    * it does it wrong, we'll be able to do it right, as soon as all the
  1445. +    * other data has been written.. */
  1446.   
  1447.     /* Calculate the offsets of the various pieces of the output file.  */
  1448.     compute_section_offsets ();
  1449.   
  1450. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1451. +   /* get ready to collect information where all symbols
  1452. +    * go. Since this has to be done only once, we'll later be able to 
  1453. +    * output the right symbol-hunk after the right (code/data/bss-)hunk. */
  1454. +   init_symbol_hunks ();
  1455. +   look_for_symbols ();
  1456. + #endif
  1457.     /* Output the text and data segments, relocating as we go.  */
  1458.     write_text ();
  1459.     write_data ();
  1460. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1461. +   if (datadata_relocs_offset)
  1462. +     write_datadata_relocs ();
  1463. +   write_bss ();
  1464. +   if (number_of_debug_hunk != -1)
  1465. +     {
  1466. +       /* ok, lets output the start of the debug hunk */
  1467. +       fseek (outstream, 0L, SEEK_END);
  1468. +       offset_of_debug_hunk = ftell (outstream);
  1469. +       dh.id = 0x3f1;     /* HUNK_DEBUG */
  1470. +       dh.len = 0;        /* we'll fill this in later */
  1471. +       dh.magic = ZMAGIC; /* when wishes came true... */
  1472. +       dh.syms = outheader.a_syms;
  1473. +       mywrite(&dh, sizeof dh, 1, outstream);
  1474. +       output_syms_offset   = ftell (outstream);
  1475. +       output_strs_offset   = output_syms_offset + dh.syms;
  1476. +       /* since we later will seek forward and backward to fill in each files
  1477. +        * symbol- and string-table, we have to create the needed space, that
  1478. +        * will be seeked over, since on an empty file, lseek(fd, 10, 0) will 
  1479. +        * position to byte 10 on Unix, but will just generate an error under
  1480. +        * AmigaDOS and stay at position 0. */
  1481. +       /* this will just write garbage, but thats enough:-)) */
  1482. +       mywrite(&output_strs_offset, dh.syms+4, 1, outstream);
  1483. +       fseek (outstream, output_syms_offset, 0);
  1484. +     }
  1485. + #endif
  1486.   
  1487.     /* Output the merged relocation info, if requested with `-r'.  */
  1488. ***************
  1489. *** 4548,4559 ****
  1490.     compute_more_section_offsets ();
  1491.   
  1492.     /* Copy any GDB symbol segments from input files.  */
  1493.     write_symsegs ();
  1494.   
  1495.     /* Now that everything is known about the output file, write its header.  */
  1496.     write_header ();
  1497.   
  1498. !   close (outdesc);
  1499.   
  1500.     mask = umask (0);
  1501.     umask (mask);
  1502. --- 5058,5077 ----
  1503.     compute_more_section_offsets ();
  1504.   
  1505. + #ifndef HUNK_INSTEAD_OF_A_OUT
  1506. +   /* I don't support GDB-symbol segments, they aren't used anymore by
  1507. +    * the newer versions of gdb, BUT of course, if somebody needs them..
  1508. +    * that's exactly why I introduced the "dh.strs" Parameter, so that
  1509. +    * you could - as in Unix - append these segments at the end of the file */
  1510.     /* Copy any GDB symbol segments from input files.  */
  1511.     write_symsegs ();
  1512. + #endif
  1513.   
  1514.     /* Now that everything is known about the output file, write its header.  */
  1515.     write_header ();
  1516.   
  1517. !   fclose (outstream);
  1518.   
  1519. + #ifndef HUNK_INSTEAD_OF_A_OUT
  1520.     mask = umask (0);
  1521.     umask (mask);
  1522. ***************
  1523. *** 4561,4567 ****
  1524.     if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
  1525.       perror_name (output_filename);
  1526.   }
  1527.   void modify_location (), perform_relocation (), copy_text (), copy_data ();
  1528.   
  1529.   /* Relocate the text segment of each input file
  1530. --- 5079,5089 ----
  1531.     if (chmod (output_filename, filemode | (0111 & ~mask)) == -1)
  1532.       perror_name (output_filename);
  1533. + #endif
  1534.   }
  1535.   void modify_location (), perform_relocation (), copy_text (), copy_data ();
  1536. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1537. + void write_hunk_header();
  1538. + #endif
  1539.   
  1540.   /* Relocate the text segment of each input file
  1541. ***************
  1542. *** 4574,4580 ****
  1543.       fprintf (stderr, "Copying and relocating text:\n\n");
  1544.   
  1545. !   lseek (outdesc, output_text_offset + text_header_size, 0);
  1546.   
  1547.     each_full_file (copy_text, 0);
  1548.     file_close ();
  1549.   
  1550. --- 5096,5133 ----
  1551.       fprintf (stderr, "Copying and relocating text:\n\n");
  1552.   
  1553. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1554. !   /* this is a definitive write, we don't need to rewrite this out, since
  1555. !    * the yet undefined sizes of the reloc-hunks don't go into the 
  1556. !    * header-hunk */
  1557. !   write_hunk_header(outstream);
  1558. !   init_reloc_hunk();
  1559. !   /* and if there's no code-hunk, we can return here.. no sense in
  1560. !    * complicately doing just nothing... */
  1561. !   if (number_of_code_hunk == -1) return;
  1562. !   /* else start the code-hunk */
  1563. !   {
  1564. !      long code_header[2];
  1565. !      code_header[0] = 0x3e9;
  1566. !      code_header[1] = LONGSIZE(text_size);
  1567. !      mywrite(code_header, 1, sizeof code_header, outstream);
  1568. !   }
  1569. ! #else
  1570. !   fseek (outstream, output_text_offset + text_header_size, 0);
  1571. ! #endif
  1572.   
  1573.     each_full_file (copy_text, 0);
  1574. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1575. +   if (output_datadata_relocs && numdatadata_relocs)
  1576. +     {
  1577. +       int i, zero = 0;
  1578. +       /* include the size-field, -> <= . The `real' values come later */
  1579. +       datadata_relocs_offset = ftell (outstream);
  1580. +       for (i = 0; i <= numdatadata_relocs; i ++)
  1581. +         mywrite (&zero, 1, sizeof (long), outstream);
  1582. +     }
  1583. + #endif
  1584.     file_close ();
  1585.   
  1586. ***************
  1587. *** 4582,4586 ****
  1588.       fprintf (stderr, "\n");
  1589.   
  1590. !   padfile (text_pad, outdesc);
  1591.   }
  1592.   
  1593. --- 5135,5148 ----
  1594.       fprintf (stderr, "\n");
  1595.   
  1596. !   padfile (text_pad, outstream);
  1597. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1598. !   write_reloc_hunk();
  1599. !   write_symbol_hunk(number_of_code_hunk);
  1600. !   {
  1601. !     long hunk_end = 0x3f2;
  1602. !     mywrite(&hunk_end, 1, sizeof(long), outstream);
  1603. !   }
  1604. ! #endif
  1605.   }
  1606.   
  1607. ***************
  1608. *** 4687,4691 ****
  1609.   
  1610.     /* Relocate the text according to the text relocation.  */
  1611.     perform_relocation (bytes, entry->text_start_address - entry->orig_text_address,
  1612.                 entry->text_size, reloc, entry->text_reloc_size, entry);
  1613. --- 5249,5252 ----
  1614. ***************
  1615. *** 4693,4699 ****
  1616.     /* Write the relocated text to the output file.  */
  1617.   
  1618. !   mywrite (bytes, 1, entry->text_size, outdesc);
  1619.   }
  1620.   /* Relocate the data segment of each input file
  1621.      and write to the output file.  */
  1622. --- 5254,5260 ----
  1623.     /* Write the relocated text to the output file.  */
  1624.   
  1625. !   mywrite (bytes, 1, entry->text_size, outstream);
  1626.   }
  1627.   /* Relocate the data segment of each input file
  1628.      and write to the output file.  */
  1629. ***************
  1630. *** 4705,4709 ****
  1631.       fprintf (stderr, "Copying and relocating data:\n\n");
  1632.   
  1633. !   lseek (outdesc, output_data_offset, 0);
  1634.   
  1635.     each_full_file (copy_data, 0);
  1636. --- 5266,5290 ----
  1637.       fprintf (stderr, "Copying and relocating data:\n\n");
  1638.   
  1639. ! #ifndef HUNK_INSTEAD_OF_A_OUT
  1640. !   fseek (outstream, output_data_offset, 0);
  1641. ! #else
  1642. !   /* just have to hope that the file is positioned correctly.. */
  1643. !   init_reloc_hunk();
  1644. !   /* start a data-hunk, if there is data to be output */
  1645. !   if (number_of_data_hunk == -1) return;
  1646. !   {
  1647. !     long data_header[2];
  1648. !     int size;
  1649. !     data_header[0] = 0x3ea;
  1650. !     size = LONGSIZE(data_size);
  1651. !     /* create long data hunk? */
  1652. !     if (long_data_hunk && databss_together)
  1653. !       size=LONGSIZE(data_size+bss_size);
  1654. !     data_header[1] = size;
  1655. !       
  1656. !     mywrite(data_header, 1, sizeof data_header, outstream);
  1657. !   }
  1658. ! #endif
  1659.   
  1660.     each_full_file (copy_data, 0);
  1661. ***************
  1662. *** 4714,4724 ****
  1663.   
  1664.     if (set_vector_count)
  1665. !     mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
  1666. !          sizeof (unsigned long), outdesc);
  1667.   
  1668.     if (trace_files)
  1669.       fprintf (stderr, "\n");
  1670.   
  1671. !   padfile (data_pad, outdesc);
  1672.   }
  1673.   
  1674. --- 5295,5337 ----
  1675.   
  1676.     if (set_vector_count)
  1677. !     {
  1678. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1679. !      /* this and mywrite later: inverted set_symbol_count and 
  1680. !       * set_vector_count, guess they were mixed up before   ### mw */
  1681. !       relocate_set_vectors (set_vectors, rel_vectors,
  1682. !                 2 * set_vector_count + set_symbol_count);
  1683. ! #endif
  1684. ! #if 0
  1685. !       mywrite (set_vectors, 2 * set_symbol_count + set_vector_count,
  1686. !            sizeof (unsigned long), outstream);
  1687. ! #else
  1688. !       mywrite (set_vectors, 2 * set_vector_count + set_symbol_count,
  1689. !            sizeof (unsigned long), outstream);
  1690. ! #endif
  1691. !     }
  1692.   
  1693.     if (trace_files)
  1694.       fprintf (stderr, "\n");
  1695.   
  1696. !   padfile (data_pad, outstream);
  1697. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1698. !   if (long_data_hunk && databss_together && bss_size)
  1699. !     {
  1700. !       /* dump zeros */
  1701. !       int i, zero = 0;
  1702. !       for (i = 0; i < LONGSIZE(bss_size); i++)
  1703. !     mywrite (&zero, 1, sizeof (long), outstream);
  1704. !     }
  1705. !   write_reloc_hunk();
  1706. !   write_symbol_hunk(number_of_data_hunk);
  1707. !   {
  1708. !     long hunk_end = 0x3f2;
  1709. !     mywrite(&hunk_end, 1, sizeof(long), outstream);
  1710. !   }
  1711. ! #endif
  1712.   }
  1713.   
  1714. ***************
  1715. *** 4766,4775 ****
  1716.       fatal_with_file ("premature eof in data section of ", entry);
  1717.   
  1718. !   perform_relocation (bytes, entry->data_start_address - entry->orig_data_address,
  1719. !               entry->data_size, reloc, entry->data_reloc_size, entry);
  1720.   
  1721. !   mywrite (bytes, 1, entry->data_size, outdesc);
  1722.   }
  1723.   /* Relocate ENTRY's text or data section contents.
  1724.      DATA is the address of the contents, in core.
  1725. --- 5379,5392 ----
  1726.       fatal_with_file ("premature eof in data section of ", entry);
  1727.   
  1728. !   perform_relocation (bytes, entry->data_start_address 
  1729. ! #ifndef HUNK_INSTEAD_OF_A_OUT
  1730. !                         - entry->orig_data_address
  1731. ! #endif
  1732. !                                     ,
  1733. !                 entry->data_size, reloc, entry->data_reloc_size, entry);
  1734.   
  1735. !   mywrite (bytes, 1, entry->data_size, outstream);
  1736.   }
  1737.   /* Relocate ENTRY's text or data section contents.
  1738.      DATA is the address of the contents, in core.
  1739. ***************
  1740. *** 4797,4800 ****
  1741. --- 5414,5421 ----
  1742.     int bss_relocation = entry->bss_start_address - entry->orig_bss_address;
  1743.   
  1744. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1745. +   int this_hunk;
  1746. + #endif
  1747.     for (; p < end; p++)
  1748.       {
  1749. ***************
  1750. *** 4802,4805 ****
  1751. --- 5423,5431 ----
  1752.         register int addr = RELOC_ADDRESS(p);
  1753.         register unsigned int mask = 0;
  1754. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1755. +       int ext_abs;
  1756. +       
  1757. +       ext_abs = 0;
  1758. + #endif
  1759.   
  1760.         if (addr >= data_size)
  1761. ***************
  1762. *** 4828,4831 ****
  1763. --- 5454,5489 ----
  1764.         else
  1765.           relocation = sp->value;
  1766. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1767. +       if ((sp->defined & ~N_EXT) == N_ABS)
  1768. +         /* sort of a kludge.. the only external symbol (not pcrelative)
  1769. +              * we can really resolve.. */
  1770. +         ext_abs = 1;
  1771. +       else if ((sp->defined & ~N_EXT) == N_TEXT ||
  1772. +           (sp->defined & ~N_EXT) == N_SETT)
  1773. +         {
  1774. +           this_hunk = number_of_code_hunk;
  1775. +           if (RELOC_BASEREL_P (p))
  1776. +             {
  1777. +               fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
  1778. +                          p->r_symbolnum, p->r_extern, p->r_address);
  1779. +           fatal_with_file ("base relative text relocation in ", entry);
  1780. +         }
  1781. +         }
  1782. +       else if ((sp->defined & ~N_EXT) == N_DATA ||
  1783. +                (sp->defined & ~N_EXT) == N_SETD ||
  1784. +            (sp->defined & ~N_EXT) == N_SETV)
  1785. +         {
  1786. +           this_hunk = number_of_data_hunk;
  1787. +         }
  1788. +       else if ((sp->defined & ~N_EXT) == N_BSS ||
  1789. +            (sp->defined & ~N_EXT) == N_UNDF ||
  1790. +                (sp->defined & ~N_EXT) == N_SETB)
  1791. +         {
  1792. +           this_hunk = number_of_bss_hunk;
  1793. +         }
  1794. +       else    
  1795. +         fatal_with_file ("external symbol with unknown type $%x in ", entry, sp->defined);
  1796. + #endif
  1797.       }
  1798.         else switch (RELOC_TYPE(p))
  1799. ***************
  1800. *** 4833,4847 ****
  1801.       case N_TEXT:
  1802.       case N_TEXT | N_EXT:
  1803. !       relocation = text_relocation;
  1804.         break;
  1805.   
  1806.       case N_DATA:
  1807.       case N_DATA | N_EXT:
  1808. !       relocation = data_relocation;
  1809.         break;
  1810.   
  1811.       case N_BSS:
  1812.       case N_BSS | N_EXT:
  1813. !       relocation = bss_relocation;
  1814.         break;
  1815.   
  1816. --- 5491,5531 ----
  1817.       case N_TEXT:
  1818.       case N_TEXT | N_EXT:
  1819. !       if (RELOC_BASEREL_P (p))
  1820. !         {
  1821. !           fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
  1822. !                      p->r_symbolnum, p->r_extern, p->r_address);
  1823. !           fatal_with_file ("base relative text relocation in ", entry);
  1824. !         }
  1825. !       else
  1826. !         relocation = text_relocation;
  1827. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1828. !       this_hunk = number_of_code_hunk;
  1829. ! #endif
  1830.         break;
  1831.   
  1832.       case N_DATA:
  1833.       case N_DATA | N_EXT:
  1834. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1835. !       if (RELOC_BASEREL_P (p))
  1836. !         relocation = entry->data_start_address;
  1837. !       else
  1838. ! #endif
  1839. !         relocation = data_relocation;
  1840. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1841. !       this_hunk = number_of_data_hunk;
  1842. ! #endif
  1843.         break;
  1844.   
  1845.       case N_BSS:
  1846.       case N_BSS | N_EXT:
  1847. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1848. !       if (RELOC_BASEREL_P (p))
  1849. !         relocation = entry->bss_start_address - entry->data_size;
  1850. !       else
  1851. ! #endif
  1852. !         relocation = bss_relocation;
  1853. ! #ifdef HUNK_INSTEAD_OF_A_OUT
  1854. !       this_hunk = number_of_bss_hunk;
  1855. ! #endif
  1856.         break;
  1857.   
  1858. ***************
  1859. *** 4855,4861 ****
  1860. --- 5539,5570 ----
  1861.       }
  1862.   
  1863. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1864. +       /* in this case, ONLY relocate those pc-relative 32bit jumps, that
  1865. +        * gas generates, since they are position independent, this gives
  1866. +        * a HUGE.. 'if' inside of '#ifdef' oh well... */
  1867. +       if (RELOC_PCREL_P(p) || RELOC_BASEREL_P(p) || ext_abs) {
  1868. +       
  1869. +       /* VERY BIG KLUDGE AHEAD! Since this amiga hunk format is really
  1870. +        * limited, 8bit and 16bit references are always defined to be
  1871. +        * pc-relative (according to the AmigaDOS RM 2nd ed). BUT if such
  1872. +        * a symbol is resolved by an absolute symbol then it's not considered
  1873. +        * to be pc-relative any more. This is nowhere documented, but you
  1874. +        * couldn't get
  1875. +        *   jsr _LVOOpen(a6)
  1876. +        * to work if you wouldn't do it this way. */
  1877. +        if (ext_abs) RELOC_PCREL_P(p) = 0;
  1878. +       
  1879. + #endif
  1880.         if (RELOC_PCREL_P(p))
  1881.       relocation -= pc_relocation;
  1882.   
  1883. +       /* if base relative, subtract 64k/2, so we get a larger range */
  1884. +       if (RELOC_BASEREL_P(p))
  1885. +     {
  1886. +       if (! databss_together)
  1887. +         fatal_with_file ("Reloc is base relative. Specify -databss-together in ", entry);
  1888. +       relocation -= 0x7ffe;
  1889. +     }
  1890.   #ifdef RELOC_ADD_EXTRA
  1891.         relocation += RELOC_ADD_EXTRA(p);
  1892. ***************
  1893. *** 4896,4900 ****
  1894.         relocation <<= RELOC_TARGET_BITPOS(p);
  1895.         mask <<= RELOC_TARGET_BITPOS(p);
  1896.         switch (RELOC_TARGET_SIZE(p))
  1897.       {
  1898. --- 5605,5608 ----
  1899. ***************
  1900. *** 4904,4907 ****
  1901. --- 5612,5618 ----
  1902.         else if (RELOC_MEMORY_ADD_P(p))
  1903.           relocation += mask & *(char *) (data + addr);
  1904. +       if (relocation < -128 || relocation > 127)
  1905. +         fatal_with_file ("Byte reloc overflow in ", entry);
  1906.         *(char *) (data + addr) &= ~mask;
  1907.         *(char *) (data + addr) |= relocation;
  1908. ***************
  1909. *** 4909,4919 ****
  1910.   
  1911.       case 1:
  1912. !       if (RELOC_MEMORY_SUB_P(p))
  1913.           relocation -= mask & *(short *) (data + addr);
  1914.         else if (RELOC_MEMORY_ADD_P(p))
  1915.           relocation += mask & *(short *) (data + addr);
  1916.         *(short *) (data + addr) &= ~mask;
  1917.         *(short *) (data + addr) |= relocation;
  1918.         break;
  1919.   
  1920.       case 2:
  1921. --- 5620,5648 ----
  1922.   
  1923.       case 1:
  1924. !       {
  1925. !       int r=relocation;
  1926. !       if (RELOC_MEMORY_SUB_P(p))
  1927.           relocation -= mask & *(short *) (data + addr);
  1928.         else if (RELOC_MEMORY_ADD_P(p))
  1929.           relocation += mask & *(short *) (data + addr);
  1930. +       if (relocation < -32768 || relocation > 32767)
  1931. +         {
  1932. +           fprintf (stderr, "relocation = $%lx, bsr = %d, pcr = %d, r= $%lx\n",
  1933. +                      relocation, RELOC_BASEREL_P(p), RELOC_PCREL_P (p), r);
  1934. +           fprintf (stderr, "textr = $%x, datar = $%x, bssr = $%x\n",
  1935. +                      text_relocation, data_relocation, bss_relocation);
  1936. +           fprintf (stderr, "symn = $%x, extern = %d, addr = $%lx.\n",
  1937. +                      p->r_symbolnum, p->r_extern, p->r_address);
  1938. +           fprintf (stderr, "data_size = %d, bss_size = %d.\n",
  1939. +                data_size, bss_size);
  1940. +           fatal_with_file ("Word reloc overflow in ", entry);
  1941. +         }
  1942.         *(short *) (data + addr) &= ~mask;
  1943.         *(short *) (data + addr) |= relocation;
  1944.         break;
  1945. +       }
  1946.   
  1947.       case 2:
  1948. ***************
  1949. *** 4938,4941 ****
  1950. --- 5667,5671 ----
  1951.         else if (RELOC_MEMORY_ADD_P(p))
  1952.           relocation += mask & *(long *) (data + addr);
  1953.         *(long *) (data + addr) &= ~mask;
  1954.         *(long *) (data + addr) |= relocation;
  1955. ***************
  1956. *** 4946,4952 ****
  1957.         fatal_with_file ("Unimplemented relocation field length in ", entry);
  1958.       }
  1959.       }
  1960.   }
  1961.   /* For OUTPUT_RELOCATABLE only: write out the relocation,
  1962.      relocating the addresses-to-be-relocated.  */
  1963. --- 5676,5713 ----
  1964.         fatal_with_file ("Unimplemented relocation field length in ", entry);
  1965.       }
  1966. + #ifdef HUNK_INSTEAD_OF_A_OUT
  1967. +     /* now finish this huge 'if' .. */
  1968. +     }
  1969. +     else
  1970. +       {
  1971. +         /* this only deals with 32bit relocs, the Amiga-loader
  1972. +          * doesn't support 1 or 2 byte relocs, they are only defined
  1973. +          * inside program-units (commonly known as object-files:-)) */
  1974. +         if (RELOC_TARGET_SIZE(p) != 2)
  1975. +           fatal_with_file ("unsupported reloc-size in ", entry);
  1976. + /* Phil.B: 06-Apr-94 same kludge as above for host with stricter alignment
  1977. +    than the taget. */
  1978. + #ifdef CROSS_LINKER
  1979. +       {
  1980. +         /* Thing to relocate.  */
  1981. +         long thing;
  1982. +         bcopy (data + addr, &thing, sizeof (thing));
  1983. +         thing += relocation;
  1984. +         bcopy (&thing, data + addr, sizeof (thing));
  1985. +       }
  1986. + #else
  1987. +         *(long *) (data + addr) += relocation;
  1988. + #endif /* CROSS_LINKER */
  1989. +         addr += pc_relocation;
  1990. +             add_to_reloc_hunk(this_hunk, addr);
  1991. +       }
  1992. + #endif
  1993.       }
  1994.   }
  1995.   /* For OUTPUT_RELOCATABLE only: write out the relocation,
  1996.      relocating the addresses-to-be-relocated.  */
  1997. ***************
  1998. *** 4996,5000 ****
  1999.     /* Write out the relocations of all files, remembered from copy_text.  */
  2000.   
  2001. !   lseek (outdesc, output_trel_offset, 0);
  2002.     each_full_file (coptxtrel, 0);
  2003.   
  2004. --- 5757,5761 ----
  2005.     /* Write out the relocations of all files, remembered from copy_text.  */
  2006.   
  2007. !   fseek (outstream, output_trel_offset, 0);
  2008.     each_full_file (coptxtrel, 0);
  2009.   
  2010. ***************
  2011. *** 5002,5006 ****
  2012.       fprintf (stderr, "\nWriting data relocation:\n\n");
  2013.   
  2014. !   lseek (outdesc, output_drel_offset, 0);
  2015.     each_full_file (copdatrel, 0);
  2016.   
  2017. --- 5763,5767 ----
  2018.       fprintf (stderr, "\nWriting data relocation:\n\n");
  2019.   
  2020. !   fseek (outstream, output_drel_offset, 0);
  2021.     each_full_file (copdatrel, 0);
  2022.   
  2023. ***************
  2024. *** 5077,5081 ****
  2025.   #endif
  2026.   
  2027. !   mywrite (entry->textrel, 1, entry->text_reloc_size, outdesc);
  2028.   }
  2029.   
  2030. --- 5838,5842 ----
  2031.   #endif
  2032.   
  2033. !   mywrite (entry->textrel, 1, entry->text_reloc_size, outstream);
  2034.   }
  2035.   
  2036. ***************
  2037. *** 5156,5162 ****
  2038.   #endif
  2039.   
  2040. !   mywrite (entry->datarel, 1, entry->data_reloc_size, outdesc);
  2041.   }
  2042.   void write_file_syms ();
  2043.   void write_string_table ();
  2044. --- 5917,5923 ----
  2045.   #endif
  2046.   
  2047. !   mywrite (entry->datarel, 1, entry->data_reloc_size, outstream);
  2048.   }
  2049.   void write_file_syms ();
  2050.   void write_string_table ();
  2051. ***************
  2052. *** 5193,5198 ****
  2053.   }
  2054.   
  2055. - FILE *outstream = (FILE *) 0;
  2056.   /* Write the contents of `strtab_vector' into the string table.
  2057.      This is done once for each file's local&debugger symbols
  2058. --- 5954,5957 ----
  2059. ***************
  2060. *** 5204,5211 ****
  2061.     register int i;
  2062.   
  2063. !   lseek (outdesc, output_strs_offset + output_strs_size, 0);
  2064.   
  2065.     if (!outstream)
  2066.       outstream = fdopen (outdesc, "w");
  2067.   
  2068.     for (i = 0; i < strtab_index; i++)
  2069. --- 5963,5972 ----
  2070.     register int i;
  2071.   
  2072. !   fseek (outstream, output_strs_offset + output_strs_size, 0);
  2073.   
  2074. + #if 0
  2075.     if (!outstream)
  2076.       outstream = fdopen (outdesc, "w");
  2077. + #endif
  2078.   
  2079.     for (i = 0; i < strtab_index; i++)
  2080. ***************
  2081. *** 5221,5225 ****
  2082.       perror_name (output_filename);
  2083.   }
  2084.   /* Write the symbol table and string table of the output file.  */
  2085.   
  2086. --- 5982,5986 ----
  2087.       perror_name (output_filename);
  2088.   }
  2089.   /* Write the symbol table and string table of the output file.  */
  2090.   
  2091. ***************
  2092. *** 5249,5252 ****
  2093. --- 6010,6019 ----
  2094.     register struct nlist *bufp = buf;
  2095.   
  2096. + #ifdef HUNK_INSTEAD_OF_A_OUT
  2097. +   /* this enables us to output "regular" amiga symbols without
  2098. +    * the BSD-like debug-hunk */
  2099. +   if (number_of_debug_hunk == -1) return;
  2100. + #endif
  2101.     /* Size of string table includes the bytes that store the size.  */
  2102.     strtab_size = sizeof strtab_size;
  2103. ***************
  2104. *** 5371,5376 ****
  2105.     /* Output the buffer full of `struct nlist's.  */
  2106.   
  2107. !   lseek (outdesc, output_syms_offset + output_syms_size, 0);
  2108. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outdesc);
  2109.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2110.   
  2111. --- 6138,6143 ----
  2112.     /* Output the buffer full of `struct nlist's.  */
  2113.   
  2114. !   fseek (outstream, output_syms_offset + output_syms_size, 0);
  2115. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outstream);
  2116.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2117.   
  2118. ***************
  2119. *** 5381,5386 ****
  2120.        first word of the string table.  */
  2121.   
  2122. !   lseek (outdesc, output_strs_offset, 0);
  2123. !   mywrite (&strtab_size, sizeof (int), 1, outdesc);
  2124.   
  2125.     /* Write the strings for the global symbols.  */
  2126. --- 6148,6153 ----
  2127.        first word of the string table.  */
  2128.   
  2129. !   fseek (outstream, output_strs_offset, 0);
  2130. !   mywrite (&strtab_size, sizeof (int), 1, outstream);
  2131.   
  2132.     /* Write the strings for the global symbols.  */
  2133. ***************
  2134. *** 5388,5392 ****
  2135.     write_string_table ();
  2136.   }
  2137.   /* Write the local and debugger symbols of file ENTRY.
  2138.      Increment *SYMS_WRITTEN_ADDR for each symbol that is written.  */
  2139. --- 6155,6159 ----
  2140.     write_string_table ();
  2141.   }
  2142.   /* Write the local and debugger symbols of file ENTRY.
  2143.      Increment *SYMS_WRITTEN_ADDR for each symbol that is written.  */
  2144. ***************
  2145. *** 5490,5495 ****
  2146.     /* All the symbols are now in BUF; write them.  */
  2147.   
  2148. !   lseek (outdesc, output_syms_offset + output_syms_size, 0);
  2149. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outdesc);
  2150.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2151.   
  2152. --- 6257,6262 ----
  2153.     /* All the symbols are now in BUF; write them.  */
  2154.   
  2155. !   fseek (outstream, output_syms_offset + output_syms_size, 0);
  2156. !   mywrite (buf, sizeof (struct nlist), bufp - buf, outstream);
  2157.     output_syms_size += sizeof (struct nlist) * (bufp - buf);
  2158.   
  2159. ***************
  2160. *** 5500,5504 ****
  2161.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  2162.   }
  2163.   /* Copy any GDB symbol segments from the input files to the output file.
  2164.      The contents of the symbol segment is copied without change
  2165. --- 6267,6271 ----
  2166.     entry->strings = 0;        /* Since it will dissapear anyway.  */
  2167.   }
  2168.   /* Copy any GDB symbol segments from the input files to the output file.
  2169.      The contents of the symbol segment is copied without change
  2170. ***************
  2171. *** 5510,5514 ****
  2172.   write_symsegs ()
  2173.   {
  2174. !   lseek (outdesc, output_symseg_offset, 0);
  2175.     each_file (write_file_symseg, 0);
  2176.   }
  2177. --- 6277,6281 ----
  2178.   write_symsegs ()
  2179.   {
  2180. !   fseek (outstream, output_symseg_offset, 0);
  2181.     each_file (write_file_symseg, 0);
  2182.   }
  2183. ***************
  2184. *** 5545,5549 ****
  2185.     /* Write the modified root into the output file.  */
  2186.   
  2187. !   mywrite (&root, sizeof root, 1, outdesc);
  2188.   
  2189.     /* Copy the rest of the symbol segment unchanged.  */
  2190. --- 6312,6316 ----
  2191.     /* Write the modified root into the output file.  */
  2192.   
  2193. !   mywrite (&root, sizeof root, 1, outstream);
  2194.   
  2195.     /* Copy the rest of the symbol segment unchanged.  */
  2196. ***************
  2197. *** 5558,5567 ****
  2198.       fatal_with_file ("premature end of file in symbol segment of ", entry);
  2199.         total -= len;
  2200. !       mywrite (buffer, len, 1, outdesc);
  2201.       }
  2202.   
  2203.     file_close ();
  2204.   }
  2205.   /* Define a special symbol (etext, edata, or end).  NAME is the
  2206.      name of the symbol, with a leading underscore (whether or not this
  2207. --- 6325,6334 ----
  2208.       fatal_with_file ("premature end of file in symbol segment of ", entry);
  2209.         total -= len;
  2210. !       mywrite (buffer, len, 1, outstream);
  2211.       }
  2212.   
  2213.     file_close ();
  2214.   }
  2215.   /* Define a special symbol (etext, edata, or end).  NAME is the
  2216.      name of the symbol, with a leading underscore (whether or not this
  2217. ***************
  2218. *** 5617,5620 ****
  2219. --- 6384,6413 ----
  2220.     symbol_define ("__end", N_BSS | N_EXT, &end_symbol_alt);
  2221.   
  2222. + #ifdef amigados
  2223. +   if (output_datadata_relocs)
  2224. +     symbol_define ("___datadata_relocs", N_TEXT | N_EXT, &datadata_reloc_symbol);
  2225. +   symbol_define ("__sdata", N_DATA | N_EXT, &sdata_symbol);
  2226. +   symbol_define ("___text_size", N_ABS | N_EXT, &text_size_symbol);
  2227. +   symbol_define ("___data_size", N_ABS | N_EXT, &data_size_symbol);
  2228. +   symbol_define ("___bss_size", N_ABS | N_EXT, &bss_size_symbol);
  2229. +   {
  2230. +     symbol *a_symbol;
  2231. +     symbol_define ("___machtype", N_ABS | N_EXT, &a_symbol);
  2232. +     if (a_symbol)
  2233. +       a_symbol->value = amiga_machtype;
  2234. +       
  2235. +     symbol_define ("___databss_together", N_ABS | N_EXT, &a_symbol);
  2236. +     if (a_symbol)
  2237. +       a_symbol->value = databss_together;
  2238. +       
  2239. +     if (databss_together)
  2240. +       {
  2241. +         symbol_define ("___a4_init", N_DATA | N_EXT, &a_symbol);
  2242. +         if (a_symbol)
  2243. +           a_symbol->value = data_start + 0x7ffe;
  2244. +       }
  2245. +   }
  2246. + #endif
  2247.   #ifdef sun
  2248.     {
  2249. ***************
  2250. *** 5659,5663 ****
  2251.     return k;
  2252.   }
  2253.   /* Get the symbol table entry for the global symbol named KEY.
  2254.      Create one if there is none.  */
  2255. --- 6452,6456 ----
  2256.     return k;
  2257.   }
  2258.   /* Get the symbol table entry for the global symbol named KEY.
  2259.      Create one if there is none.  */
  2260. ***************
  2261. *** 5726,5730 ****
  2262.     return 0;
  2263.   }
  2264.   /* Report a usage error.
  2265.      Like fatal except prints a usage summary.  */
  2266. --- 6519,6523 ----
  2267.     return 0;
  2268.   }
  2269.   /* Report a usage error.
  2270.      Like fatal except prints a usage summary.  */
  2271. ***************
  2272. *** 5740,5743 ****
  2273. --- 6533,6546 ----
  2274.         fprintf (stderr, "\n");
  2275.       }
  2276. + #ifdef HUNK_INSTEAD_OF_A_OUT
  2277. +   fprintf (stderr, "\
  2278. + Usage: %s [-d] [-dc] [-dp] [-e symbol] [-l lib] [-n] [-noinhibit-exec]\n\
  2279. +        [-nostdlib] [-o file] [-r] [-s] [-t] [-u symbol] [-x] [-y symbol]\n\
  2280. +        [-z] [-A file] [-Bstatic] [-D size] [-L libdir] [-M] [-N]\n\
  2281. +        [-S] [-T[{text,data}] addr] [-V prefix] [-X] \n\
  2282. +        [{-a,-amiga-debug-hunk}] [{-f,-flavor} flavor] [file...]\n\
  2283. +        [-chip {c,d,b}] [-fast {c,d,b}] [-m,-shortdata]\n",
  2284. +        progname);
  2285. + #else
  2286.     fprintf (stderr, "\
  2287.   Usage: %s [-d] [-dc] [-dp] [-e symbol] [-l lib] [-n] [-noinhibit-exec]\n\
  2288. ***************
  2289. *** 5746,5749 ****
  2290. --- 6549,6553 ----
  2291.          [-S] [-T[{text,data}] addr] [-V prefix] [-X] [file...]\n",
  2292.          progname);
  2293. + #endif
  2294.     exit (1);
  2295.   }
  2296. ***************
  2297. *** 5766,5775 ****
  2298.   
  2299.   void
  2300. ! fatal_with_file (string, entry)
  2301.        char *string;
  2302.        struct file_entry *entry;
  2303.   {
  2304.     fprintf (stderr, "%s: ", progname);
  2305. !   fprintf (stderr, string);
  2306.     print_file_name (entry, stderr);
  2307.     fprintf (stderr, "\n");
  2308. --- 6570,6579 ----
  2309.   
  2310.   void
  2311. ! fatal_with_file (string, entry, arg)
  2312.        char *string;
  2313.        struct file_entry *entry;
  2314.   {
  2315.     fprintf (stderr, "%s: ", progname);
  2316. !   fprintf (stderr, string, arg);
  2317.     print_file_name (entry, stderr);
  2318.     fprintf (stderr, "\n");
  2319. ***************
  2320. *** 5785,5793 ****
  2321.   {
  2322.     extern int errno, sys_nerr;
  2323. -   extern char *sys_errlist[];
  2324.     char *s;
  2325.   
  2326.     if (errno < sys_nerr)
  2327. !     s = concat ("", sys_errlist[errno], " for %s");
  2328.     else
  2329.       s = "cannot open %s";
  2330. --- 6589,6596 ----
  2331.   {
  2332.     extern int errno, sys_nerr;
  2333.     char *s;
  2334.   
  2335.     if (errno < sys_nerr)
  2336. !     s = concat ("", strerror (errno), " for %s");
  2337.     else
  2338.       s = "cannot open %s";
  2339. ***************
  2340. *** 5803,5811 ****
  2341.   {
  2342.     extern int errno, sys_nerr;
  2343. -   extern char *sys_errlist[];
  2344.     char *s;
  2345.   
  2346.     if (errno < sys_nerr)
  2347. !     s = concat ("", sys_errlist[errno], " for ");
  2348.     else
  2349.       s = "cannot open ";
  2350. --- 6606,6613 ----
  2351.   {
  2352.     extern int errno, sys_nerr;
  2353.     char *s;
  2354.   
  2355.     if (errno < sys_nerr)
  2356. !     s = concat ("", strerror (errno), " for ");
  2357.     else
  2358.       s = "cannot open ";
  2359. ***************
  2360. *** 5825,5839 ****
  2361.   }
  2362.   
  2363.   /* Output COUNT*ELTSIZE bytes of data at BUF
  2364.      to the descriptor DESC.  */
  2365.   
  2366.   void
  2367. ! mywrite (buf, count, eltsize, desc)
  2368.        char *buf;
  2369.        int count;
  2370.        int eltsize;
  2371. !      int desc;
  2372.   {
  2373.     register int val;
  2374.     register int bytes = count * eltsize;
  2375. --- 6627,6642 ----
  2376.   }
  2377.   
  2378.   /* Output COUNT*ELTSIZE bytes of data at BUF
  2379.      to the descriptor DESC.  */
  2380.   
  2381.   void
  2382. ! mywrite (buf, count, eltsize, stream)
  2383.        char *buf;
  2384.        int count;
  2385.        int eltsize;
  2386. !      FILE *stream;
  2387.   {
  2388. + #if 0
  2389.     register int val;
  2390.     register int bytes = count * eltsize;
  2391. ***************
  2392. *** 5847,5859 ****
  2393.         bytes -= val;
  2394.       }
  2395.   }
  2396.   
  2397. ! /* Output PADDING zero-bytes to descriptor OUTDESC.
  2398.      PADDING may be negative; in that case, do nothing.  */
  2399.   
  2400.   void
  2401. ! padfile (padding, outdesc)
  2402.        int padding;
  2403. !      int outdesc;
  2404.   {
  2405.     register char *buf;
  2406. --- 6650,6665 ----
  2407.         bytes -= val;
  2408.       }
  2409. + #else
  2410. +   fwrite (buf, eltsize, count, stream);
  2411. + #endif
  2412.   }
  2413.   
  2414. ! /* Output PADDING zero-bytes to descriptor OUTSTREAM.
  2415.      PADDING may be negative; in that case, do nothing.  */
  2416.   
  2417.   void
  2418. ! padfile (padding, outstream)
  2419.        int padding;
  2420. !      FILE *outstream;
  2421.   {
  2422.     register char *buf;
  2423. ***************
  2424. *** 5863,5867 ****
  2425.     buf = (char *) alloca (padding);
  2426.     bzero (buf, padding);
  2427. !   mywrite (buf, padding, 1, outdesc);
  2428.   }
  2429.   
  2430. --- 6669,6673 ----
  2431.     buf = (char *) alloca (padding);
  2432.     bzero (buf, padding);
  2433. !   mywrite (buf, padding, 1, outstream);
  2434.   }
  2435.   
  2436. ***************
  2437. *** 5904,5909 ****
  2438.        int size;
  2439.   {
  2440.     register char *result = malloc (size);
  2441. !   if (!result)
  2442.       fatal ("virtual memory exhausted", 0);
  2443.     return result;
  2444. --- 6710,6716 ----
  2445.        int size;
  2446.   {
  2447. +   extern char *malloc();
  2448.     register char *result = malloc (size);
  2449. !   if (!result && size)
  2450.       fatal ("virtual memory exhausted", 0);
  2451.     return result;
  2452. ***************
  2453. *** 5917,5926 ****
  2454.        int size;
  2455.   {
  2456. !   register char *result = realloc (ptr, size);
  2457.     if (!result)
  2458.       fatal ("virtual memory exhausted", 0);
  2459.     return result;
  2460.   }
  2461.   #ifdef USG
  2462.   
  2463. --- 6724,6734 ----
  2464.        int size;
  2465.   {
  2466. !   extern char *malloc(), *realloc();
  2467. !   register char *result = ptr ? realloc (ptr, size) : malloc (size);
  2468.     if (!result)
  2469.       fatal ("virtual memory exhausted", 0);
  2470.     return result;
  2471.   }
  2472.   #ifdef USG
  2473.   
  2474. ***************
  2475. *** 5953,5954 ****
  2476. --- 6761,7409 ----
  2477.   }
  2478.   #endif
  2479. + #ifdef HUNK_INSTEAD_OF_A_OUT
  2480. + /* the whole rest of the file is used for managment of hunks and subhunks.. */
  2481. + /* this is the amiga-equivalent of struct exec */
  2482. + struct simple_hunk_header {
  2483. +   long    id,    /* this will be 0x3f3 */
  2484. +     zero,
  2485. +     table_size,
  2486. +     first_hunk,
  2487. +     last_hunk,
  2488. +     sizes[4];   /* there can be at most a code,data,bss & debug hunk */
  2489. + };
  2490. + /* this writes out a hunk header, depending on the information collected
  2491. +  * so far, it will only create hunks, that really exist, so if your data-
  2492. +  * size is zero, you won't get a data-hunk at all. */
  2493. + void
  2494. + write_hunk_header(outfd)
  2495. +     int outfd;
  2496. + {
  2497. +   struct simple_hunk_header sh;
  2498. +   int this_hunk, header_size;
  2499. +   sh.id = 0x3f3;    /* HUNK_HEADER */
  2500. +   sh.zero = 0;
  2501. +   sh.table_size = current_hunk;
  2502. +   sh.first_hunk = 0;
  2503. +   sh.last_hunk  = current_hunk - 1;
  2504. +   this_hunk = 0;
  2505. +   if (number_of_code_hunk != -1)
  2506. +      sh.sizes[this_hunk++] = code_mem_type|LONGSIZE(text_size);
  2507. +   if (number_of_data_hunk != -1)
  2508. +   {
  2509. +      int size = LONGSIZE(data_size);
  2510. +      if (databss_together)
  2511. +      {
  2512. +        if (long_data_hunk || !output_datadata_relocs)
  2513. +          size=LONGSIZE(data_size+bss_size);
  2514. +        if (data_mem_type == 0)
  2515. +          data_mem_type=bss_mem_type;
  2516. +      }
  2517. +      sh.sizes[this_hunk++] = data_mem_type|size;
  2518. +   }
  2519. +   if (!databss_together && number_of_bss_hunk  != -1)
  2520. +      sh.sizes[this_hunk++] = bss_mem_type|LONGSIZE(bss_size);
  2521. +   if (number_of_debug_hunk != -1)
  2522. +      sh.sizes[this_hunk++] = 0;  /* to be filled in later */
  2523. +   header_size = sizeof(sh) - (4-this_hunk)*sizeof(long);
  2524. +   mywrite(&sh, 1, header_size, outfd);
  2525. + }
  2526. + /* if we really write out a debug hunk, this fills in the remaining
  2527. +  * spots, that are known only at the end of load-file output */
  2528. + void
  2529. + conditionally_rewrite_headers ()
  2530. + {
  2531. +   long size_of_debug_hunk,
  2532. +        end_hunk = 0x3f2,
  2533. +        eof;
  2534. +   /* if we don't want a debug hunk, just return */
  2535. +   if (number_of_debug_hunk == -1)  return;
  2536. +   /* while we're at it, since we started the debug-hunk, lets finish it
  2537. +    * now. */
  2538. +   fseek (outstream, 0L, 2);
  2539. +   eof = ftell (outstream);
  2540. +   dh.strs = eof - offset_of_debug_hunk - sizeof(dh) - dh.syms;
  2541. +   /* just to be sure, we HAVE to pad to a long-boundery */
  2542. +   if (eof & 3)
  2543. +     {
  2544. +       long zero = 0;
  2545. +       mywrite(&zero, 4 - (eof & 3), 1, outstream);
  2546. +       eof = (eof + 3) & ~3;
  2547. +     }
  2548. +   mywrite(&end_hunk, sizeof(long), 1, outstream);
  2549. +   /* ok, so calculate the size of the debug hunk. This is the 
  2550. +    * size of the debug_header plus the symbol and string tables,
  2551. +    * but it doesn't include the 2 longs, that identify the hunk and
  2552. +    * its length, whence the "- 2*sizeof(long)" */
  2553. +   size_of_debug_hunk = eof - offset_of_debug_hunk - 2*sizeof(long);
  2554. +   /* we actually need the size in longs.. */
  2555. +   size_of_debug_hunk = LONGSIZE(size_of_debug_hunk);
  2556. +   /* now first patch the debug-hunk itself, afterwards the load-file header */
  2557. +   fseek (outstream, offset_of_debug_hunk, 0);
  2558. +   dh.len = size_of_debug_hunk;
  2559. +   mywrite(&dh, sizeof dh, 1, outstream);
  2560. +   /* now the main header, this involves calculating, at which offset we
  2561. +    * find the index for the debug hunk */   
  2562. +   fseek (outstream, (5 + number_of_debug_hunk)*sizeof(long), 0);
  2563. +   mywrite(&size_of_debug_hunk, sizeof(long), 1, outstream);
  2564. +   fseek (outstream, 0L, 2);
  2565. +   /* that's it! */
  2566. + }
  2567. + /* this is the only information that we can store in a regular amiga
  2568. +  * symbol, just its value, nothing further, that's why I added the 
  2569. +  * debug-hunk-feature */
  2570. + typedef struct {
  2571. +   char *sym_name;
  2572. +   long  sym_offset;
  2573. + } simple_symbol;
  2574. + /* we'll only define symbols after at most 3 hunks, ie. the code, data
  2575. +  * and bss hunk, but not after the debug hunk, whence the index 3 */
  2576. + simple_symbol *hunk_sym_tab[3];
  2577. + int hunk_sym_tab_size[3], hunk_sym_tab_index[3];
  2578. + void
  2579. + init_symbol_hunks()
  2580. + {
  2581. +   int i;
  2582. +   if (trace_files) fprintf(stderr, "init_symbol_hunks()\n");
  2583. +   for (i = 0; i < 3; i++)
  2584. +     {
  2585. +        hunk_sym_tab[i] = 
  2586. +          (simple_symbol *) xmalloc((hunk_sym_tab_size[i] = 10) * 
  2587. +        sizeof(simple_symbol));
  2588. +        hunk_sym_tab_index[i] = 0;
  2589. +     }
  2590. + }
  2591. + /* this should go into libc, well, it wasn't there, so... */
  2592. + char *
  2593. + strsave(str)
  2594. +     char *str;
  2595. + {
  2596. +   char *cp;
  2597. +   int len = strlen(str);
  2598. +   if (len)
  2599. +     {
  2600. +       cp = xmalloc(len+1);
  2601. +       strcpy(cp, str);
  2602. +     }
  2603. +   else
  2604. +     cp = NULL;
  2605. +   return cp;
  2606. + }
  2607. + void
  2608. + add_to_symbol_hunk(hunk_num, name, offset)
  2609. +     int hunk_num;
  2610. +     char *name;
  2611. +     long offset;
  2612. + {
  2613. +    if (hunk_num == -1) return;
  2614. +    if (hunk_num >= 3) fatal ("invalid hunk_number: %d\n", hunk_num);
  2615. +    /* no checks for duplicate symbols. Since it is legitimate to have
  2616. +     * symbols with the same name, we can't strip them.. just make 
  2617. +     * sure not to call this function multiple times with the same
  2618. +     * symbol, since it won't be detected, and you'll get several
  2619. +     * labels for the same offset...
  2620. +     */
  2621. +     
  2622. +    if (trace_files) fprintf(stderr, "add_to_symbol_hunk(%d, %s, %d)\n",
  2623. +                 hunk_num, name, offset);
  2624. +    hunk_sym_tab[hunk_num][hunk_sym_tab_index[hunk_num]].sym_offset = offset;
  2625. +    hunk_sym_tab[hunk_num][hunk_sym_tab_index[hunk_num]++].sym_name = 
  2626. +      strsave(name);
  2627. +    if (hunk_sym_tab_index[hunk_num] == hunk_sym_tab_size[hunk_num])
  2628. +     hunk_sym_tab[hunk_num] = (simple_symbol *)
  2629. +       xrealloc(hunk_sym_tab[hunk_num],
  2630. +             (hunk_sym_tab_size[hunk_num] <<= 1) * 
  2631. +               sizeof(simple_symbol));
  2632. + }
  2633. + int
  2634. + compare_simple_symbols(l1, l2)
  2635. +     simple_symbol *l1, *l2;
  2636. + {
  2637. +   return l1->sym_offset - l2->sym_offset;
  2638. + }
  2639. + /* this writes the symbol subhunk #hunk_num, you call this just after
  2640. +  * you created your {code,data,bss}-hunk */
  2641. + void
  2642. + write_symbol_hunk(hunk_num)
  2643. +     int hunk_num;
  2644. + {
  2645. +   int i, j;
  2646. +   simple_symbol *tab;
  2647. +   long size, index;
  2648. +   if (hunk_num == -1) return;
  2649. +   if (hunk_num >= 3) fatal ("invalid hunk_number: %d\n", hunk_num);
  2650. +   
  2651. +   tab   = hunk_sym_tab[hunk_num];
  2652. +   size  = hunk_sym_tab_size[hunk_num];
  2653. +   index = hunk_sym_tab_index[hunk_num];
  2654. +    
  2655. +   /* kind of abused as general debug-flag:-) */
  2656. +   if (trace_files) fprintf(stderr, 
  2657. +                 "wsh: hnum=%d,size=%d,index=%d\n",
  2658. +                hunk_num,size,index);
  2659. +    
  2660. +   if (index > 0)
  2661. +     {
  2662. +       qsort(tab, index, sizeof(simple_symbol), compare_simple_symbols);
  2663. +       j = 0x3f0; /* HUNK_SYMBOL */
  2664. +       mywrite(&j, 1, sizeof(long), outstream);
  2665. +    
  2666. +       for (i = 0; i < index; i++)
  2667. +         {
  2668. +        register simple_symbol *ss = tab+i;
  2669. +        int len = strlen (ss->sym_name);
  2670. +        j = LONGSIZE (len);
  2671. +        mywrite(&j, 1, sizeof(long), outstream);
  2672. +        mywrite(ss->sym_name, 1, len, outstream);
  2673. +        if (len < 4*j)
  2674. +          padfile (4*j - len, outstream);
  2675. +        mywrite(&(ss->sym_offset), 1, sizeof(long), outstream);
  2676. +     }
  2677. +       j = 0;
  2678. +       mywrite(&j, 1, sizeof(long), outstream);
  2679. +     }
  2680. + }
  2681. + /* now follow the quite similar routines for dealing with
  2682. +  * reloc-subhunks, the difference to the symbol-subhunks is, that reloc
  2683. +  * subhunks can be output only after the {code,data}-Hunks, AND there
  2684. +  * can be more than one after each of them */
  2685. + long *hunk_rel_tab[3], hunk_rel_tab_size[3], hunk_rel_tab_index[3];
  2686. + void
  2687. + init_reloc_hunk()
  2688. + {
  2689. +   int i;
  2690. +   if (trace_files) fprintf(stderr, "init_reloc_hunk()\n");
  2691. +   for (i = 0; i < 3; i++)
  2692. +     {
  2693. +        hunk_rel_tab[i] = 
  2694. +          (long *) xmalloc((hunk_rel_tab_size[i] = 10) * sizeof(long));
  2695. +        hunk_rel_tab_index[i] = 0;
  2696. +     }
  2697. + }
  2698. + void
  2699. + add_to_reloc_hunk(hunk_num, offset)
  2700. +     int hunk_num;
  2701. +     long offset;
  2702. + {
  2703. +    /* no checks for duplicate symbols, they will show up when we sort
  2704. +     * the table, and we will strip them off before writing out the table */
  2705. +    if (trace_files) fprintf(stderr, "add_to_reloc_hunk(%d, %d)\n", hunk_num, offset);
  2706. +    hunk_rel_tab[hunk_num][hunk_rel_tab_index[hunk_num]++] = offset;
  2707. +    if (hunk_rel_tab_index[hunk_num] == hunk_rel_tab_size[hunk_num])
  2708. +     hunk_rel_tab[hunk_num] = (long *)
  2709. +       xrealloc(hunk_rel_tab[hunk_num],
  2710. +                    (hunk_rel_tab_size[hunk_num] <<= 1) * sizeof(long));
  2711. + }
  2712. + int
  2713. + compare_longs(l1, l2)
  2714. +     long *l1, *l2;
  2715. + {
  2716. +   return *l1 - *l2;
  2717. + }
  2718. + int
  2719. + compare_strings (s1p, s2p)
  2720. +     char **s1p;
  2721. +     char **s2p;
  2722. + {
  2723. +   return (strcmp (*s1p, *s2p));
  2724. + }
  2725. + void
  2726. + write_reloc_hunk()
  2727. + {
  2728. +    int i, j;
  2729. +    long *tab, size, index;
  2730. +    /* only write a hunk-header & -end, if we really output some relocs */
  2731. +    int did_start_hunk = 0;
  2732. +    for (i = 0; i < 3; i++)
  2733. +      {
  2734. +     tab   = hunk_rel_tab[i];
  2735. +     size  = hunk_rel_tab_size[i];
  2736. +     index = hunk_rel_tab_index[i];
  2737. +     /* kind of abused as general debug-flag:-) */
  2738. +         if (trace_files) fprintf(stderr, 
  2739. +                  "wrh: i=%d,size=%d,index=%d\n",
  2740. +                  i,size,index);
  2741. +         if (index > 0)
  2742. +       {
  2743. +         qsort(tab, index, sizeof(long), compare_longs);
  2744. +         /* kick out duplicate symbols.. I don't know, what
  2745. +          * the loader would do, if it had to relocate the same
  2746. +          * address twice.. BTW: can this happen or can't it???? */
  2747. +         for (j = 0; j < index-1; )
  2748. +           {
  2749. +         if (tab[j] == tab[j+1])
  2750. +           bcopy(tab+j+1, tab+j, ((index--)-j-1)*sizeof(long));
  2751. +         else
  2752. +           j++;
  2753. +           }
  2754. +         if (!did_start_hunk++)
  2755. +           {
  2756. +         j = 0x3ec; /* HUNK_RELOC32 */
  2757. +         mywrite(&j, 1, sizeof(long), outstream);
  2758. +           }
  2759. +         mywrite(&index, 1, sizeof(long), outstream);
  2760. +         mywrite(&i, 1, sizeof(long), outstream);
  2761. +         mywrite(tab, 1, index*sizeof(long), outstream);
  2762. +         hunk_rel_tab_index[i] = index;
  2763. +       }
  2764. +      }
  2765. +    if (did_start_hunk)
  2766. +      {
  2767. +     j = 0;
  2768. +        mywrite(&j, 1, sizeof(long), outstream);
  2769. +      }
  2770. + }
  2771. + void
  2772. + write_datadata_relocs ()
  2773. + {
  2774. +   int numdd, i, prev;
  2775. +   prev = ftell (outstream);
  2776. +   fseek (outstream, datadata_relocs_offset, L_SET);
  2777. +   
  2778. +   numdd = hunk_rel_tab_index[number_of_data_hunk];
  2779. +   if (numdd > numdatadata_relocs)
  2780. +     fatal ("found more data-data relocs than estimated!\n", 0);
  2781. +   
  2782. +   mywrite (&numdd, 1, sizeof (long), outstream);
  2783. +   if (numdd)
  2784. +     mywrite (hunk_rel_tab[number_of_data_hunk], numdd, sizeof (long), outstream);
  2785. +   fseek (outstream, prev, L_SET);
  2786. + }
  2787. + /* create the bss hunk if needed */
  2788. + void
  2789. + write_bss()
  2790. + {
  2791. +   long bss_hunk[2];
  2792. +   if (!databss_together && bss_size)
  2793. +    {
  2794. +      bss_hunk[0] = 0x3eb;
  2795. +      bss_hunk[1] = LONGSIZE(bss_size);
  2796. +      mywrite(bss_hunk, 1, sizeof bss_hunk, outstream);
  2797. +      write_symbol_hunk(number_of_bss_hunk);
  2798. +      bss_hunk[0] = 0x3f2; /* HUNK_END */
  2799. +      mywrite(bss_hunk, 1, sizeof(long), outstream);
  2800. +    }
  2801. + }
  2802. + /* this scans one object file for its symbols, and deposits them in 
  2803. +  * the symbol-hunk tables for later output */
  2804. + void
  2805. + look_for_file_syms (entry)
  2806. +      struct file_entry *entry;
  2807. + {
  2808. +   register struct nlist *p = entry->symbols;
  2809. +   register struct nlist *end = p + entry->syms_size / sizeof (struct nlist);
  2810. + #if 0
  2811. +   /* don't do this, it only confuses most amiga disassemblers.. */
  2812. +   /* Generate a local symbol for the start of this file's text.  */
  2813. +   if (discard_locals != DISCARD_ALL)
  2814. +     add_to_symbol_hunk(number_of_code_hunk, entry->local_sym_name, 
  2815. +        entry->text_start_address);
  2816. + #endif
  2817. +   /* Read the file's string table.  */
  2818. +   entry->strings = (char *) alloca (entry->strs_size);
  2819. +   read_entry_strings (file_open (entry), entry);
  2820. +   for (; p < end; p++)
  2821. +     {
  2822. +       register unsigned char type = p->n_type;
  2823. +       register int write = 0;
  2824. +       int this_hunk;
  2825. +       char *cp;
  2826. +       /* WRITE gets 1 for a non-global symbol that should be written.  */
  2827. +       if (SET_ELEMENT_P (type))    /* This occurs even if global.  These */
  2828. +                 /* types of symbols are never written */
  2829. +                 /* globally, though they are stored */
  2830. +                 /* globally.  */
  2831. +         write = output_style == OUTPUT_RELOCATABLE;
  2832. +       else if (!(type & (N_STAB | N_EXT)))
  2833. +           /* ordinary local symbol */
  2834. +       write = ((discard_locals != DISCARD_ALL)
  2835. +            && !(discard_locals == DISCARD_L &&
  2836. +                (p->n_un.n_strx + entry->strings)[0] == LPREFIX)
  2837. +            && type != N_WARNING);
  2838. +       else if (!(type & N_EXT))
  2839. +     /* debugger symbol */
  2840. +         write = (strip_symbols == STRIP_NONE);
  2841. +       /* skip STAB symbols if present */
  2842. +       write = write && !(type & N_STAB);
  2843. +       /* those weird types are NOT output in the normal symbols:-)) */
  2844. +       write = write && (type != N_ABS && type != (N_ABS|N_EXT));
  2845. +       /* don't know where those symbols come from, they're well suited to
  2846. +        * crash enforcer, and they're not `real' symbols anyway.. */
  2847. +       if (p->n_un.n_strx > entry->strs_size) continue;
  2848. +       /* symbols that end with a dot are only useful for gdb, 
  2849. +        * not for a normal amiga debugger (currently gcc_compiled. and
  2850. +        * gcc_compiled2.) so skip them in this section */
  2851. +       /* check to see, whether this string ends with a dot */
  2852. +       if (write && p->n_un.n_strx)
  2853. +         {
  2854. +           cp = rindex (p->n_un.n_strx + entry->strings, '.');
  2855. +       write = write && !(cp && !cp[1]);
  2856. +       
  2857. + #if 0
  2858. +       printf ("%s >%s<\n", write ? "adding" : "skipping", p->n_un.n_strx + entry->strings);
  2859. + #endif
  2860. +     }
  2861. +       if (write)
  2862. +     {
  2863. +       if (p->n_un.n_strx)
  2864. +         {
  2865. +           switch (type & ~N_EXT)
  2866. +             {
  2867. +           case N_TEXT:
  2868. +             this_hunk = number_of_code_hunk;
  2869. +             break;
  2870. +           case N_SETV:
  2871. +           case N_DATA:
  2872. +             this_hunk = number_of_data_hunk;
  2873. +             break;
  2874. +           case N_UNDF:
  2875. +           case N_BSS:
  2876. +             this_hunk = number_of_bss_hunk;
  2877. +             break;
  2878. +           default:
  2879. +             error ("unknown type %d while trying to build lsymhunk", type);
  2880. +             goto skip1;
  2881. +             }
  2882. +           add_to_symbol_hunk(this_hunk, p->n_un.n_strx + entry->strings,
  2883. +                  p->n_value);
  2884. + skip1:    ;
  2885. +             }
  2886. +     }
  2887. +     }
  2888. + }
  2889. + /* scan all input files for symbols and store them in the symbolhunk tables */
  2890. + void
  2891. + look_for_symbols()
  2892. + {
  2893. +   int this_hunk;
  2894. +   int i;
  2895. +   symbol *sp;
  2896. +   if (strip_symbols == STRIP_ALL)
  2897. +     return;
  2898. +   /* Write the local symbols defined by the various files.  */
  2899. +   each_file (look_for_file_syms, 0);
  2900. +   file_close ();
  2901. +   /* Scan the symbol hash table, bucket by bucket.  */
  2902. +   for (i = 0; i < TABSIZE; i++)
  2903. +     for (sp = symtab[i]; sp; sp = sp->link)
  2904. +       {
  2905. +     struct nlist nl;
  2906. +     /* Compute a `struct nlist' for the symbol.  */
  2907. +     nl.n_value = 0;
  2908. +     if (sp->defined || sp->referenced)
  2909. +       {
  2910. +         /* common condition needs to be before undefined condition */
  2911. +         /* because unallocated commons are set undefined in */
  2912. +         /* digest_symbols */
  2913. +         if (sp->defined > 1) /* defined with known type */
  2914. +           {
  2915. +         /* If the target of an indirect symbol has been
  2916. +            defined and we are outputting an executable,
  2917. +            resolve the indirection; it's no longer needed */
  2918. +         if (output_style != OUTPUT_RELOCATABLE
  2919. +             && ((sp->defined & ~N_EXT) == N_INDR)
  2920. +             && (((symbol *) sp->value)->defined > 1))
  2921. +           {
  2922. +             symbol *newsp = (symbol *) sp->value;
  2923. +             nl.n_type = newsp->defined;
  2924. +             nl.n_value = newsp->value;
  2925. +           }
  2926. +         else
  2927. +           {
  2928. +             nl.n_type = sp->defined;
  2929. +             if (sp->defined != (N_INDR | N_EXT))
  2930. +               nl.n_value = sp->value;
  2931. +             else
  2932. +               nl.n_value = 0;
  2933. +           }
  2934. +           }
  2935. +         else if (sp->max_common_size) /* defined as common but not allocated. */
  2936. +           {
  2937. +         /* happens only with -r and not -d */
  2938. +         /* write out a common definition */
  2939. +         nl.n_type = N_UNDF | N_EXT;
  2940. +         nl.n_value = sp->max_common_size;
  2941. +           }
  2942. +         else if (!sp->defined)          /* undefined -- legit only if -r */
  2943. +           {
  2944. +         nl.n_type = N_UNDF | N_EXT;
  2945. +         nl.n_value = 0;
  2946. +           }
  2947. +         else
  2948. +           fatal ("internal error: %s defined in mysterious way", sp->name);
  2949. +         switch (nl.n_type & ~N_EXT)
  2950. +           {
  2951. +         case N_TEXT:
  2952. +           this_hunk = number_of_code_hunk;
  2953. +           break;
  2954. +         case N_SETV:
  2955. +         case N_DATA:
  2956. +           this_hunk = number_of_data_hunk;
  2957. +           break;
  2958. +         case N_UNDF:
  2959. +         case N_BSS:
  2960. +           this_hunk = number_of_bss_hunk;
  2961. +           break;
  2962. +         case N_ABS:
  2963. +           break;
  2964. +         default:
  2965. +           error ("unknown type %d while trying to build symhunk", nl.n_type);
  2966. +           goto skip2;
  2967. +           }
  2968. +         /* sigh, there is no equivalent in the symbol section of a load
  2969. +          * file on the amiga, have to forget about those symbols */
  2970. +         if ((nl.n_type & ~N_EXT) == N_ABS)
  2971. +           continue;
  2972. +         add_to_symbol_hunk(this_hunk, sp->name, nl.n_value);
  2973. + skip2:    ;
  2974. +       }
  2975. +       }
  2976. + }
  2977. + void
  2978. + relocate_set_vectors (vectors, relvectors, num_entries)
  2979. +     unsigned long *vectors;
  2980. +     unsigned char *relvectors;
  2981. +     int num_entries;
  2982. + {
  2983. +   unsigned long i;
  2984. +   unsigned long offset = set_sect_start;
  2985. +   int hunk_num;
  2986. +   while (num_entries-- > 0)
  2987. +     {
  2988. +       /* the number of entries for this symbol */
  2989. +       i = *vectors++; offset += 4; relvectors++;
  2990. +       while (num_entries --, i--)
  2991. +     {
  2992. +       /* relocation ok? */
  2993. +       if (*relvectors)
  2994. +         {
  2995. +           hunk_num = number_of_code_hunk;
  2996. +           if (*vectors >= text_size)
  2997. +             {
  2998. +           if (*vectors >= text_size + data_size)
  2999. +             {
  3000. +               hunk_num = number_of_bss_hunk;
  3001. +               if (databss_together)
  3002. +                 *vectors -= text_size;
  3003. +               else
  3004. +                 *vectors -= text_size + data_size;
  3005. +             }
  3006. +           else
  3007. +             {
  3008. +               hunk_num = number_of_data_hunk;
  3009. +               *vectors -= text_size;
  3010. +             }
  3011. +             }
  3012. +           add_to_reloc_hunk (hunk_num, offset);
  3013. +         }
  3014. +       ++vectors;
  3015. +       offset += 4;
  3016. +       ++relvectors;
  3017. +     }
  3018. +       /* check.. HAS to be zero */
  3019. +       if (*vectors)
  3020. +     fatal ("set-vector corrupt, num_entries = %d", num_entries);
  3021. +       vectors++; offset += 4; relvectors++; --num_entries;
  3022. +     }
  3023. + }
  3024. + #endif
  3025. diff -2rcN binutils-1.8.x/objdump.c binutils-1.8.x-amiga/objdump.c
  3026. *** binutils-1.8.x/objdump.c    Sat Dec 30 00:16:07 1989
  3027. --- binutils-1.8.x-amiga/objdump.c    Wed Sep 22 12:45:33 1993
  3028. ***************
  3029. *** 25,30 ****
  3030.   #include "getopt.h"
  3031.   
  3032.   #ifndef COFF_ENCAPSULATE
  3033. ! #include <a.out.h>
  3034.   /* Tell a.out.gnu.h not to try to redefine some things.  */
  3035.   #define __STRUCT_EXEC_OVERRIDE__
  3036. --- 25,34 ----
  3037.   #include "getopt.h"
  3038.   
  3039. + #ifdef MCH_AMIGA
  3040. + #define getpagesize() 256
  3041. + #endif
  3042.   #ifndef COFF_ENCAPSULATE
  3043. ! #include <sun/a.out.h>
  3044.   /* Tell a.out.gnu.h not to try to redefine some things.  */
  3045.   #define __STRUCT_EXEC_OVERRIDE__
  3046. diff -2rcN binutils-1.8.x/ranlib.c binutils-1.8.x-amiga/ranlib.c
  3047. *** binutils-1.8.x/ranlib.c    Thu Mar  1 00:18:42 1990
  3048. --- binutils-1.8.x-amiga/ranlib.c    Sat Jul 30 17:15:25 1994
  3049. ***************
  3050. *** 55,59 ****
  3051.   
  3052.   char *prog = AR_PROG;
  3053. ! char *prog_pref = "/usr/local/gnubin/ar";
  3054.   
  3055.   int
  3056. --- 55,59 ----
  3057.   
  3058.   char *prog = AR_PROG;
  3059. ! char *prog_pref = "/gnu/bin/ar";
  3060.   
  3061.   int
  3062. diff -2rcN binutils-1.8.x/strip.c binutils-1.8.x-amiga/strip.c
  3063. *** binutils-1.8.x/strip.c    Mon Jun 11 21:40:01 1990
  3064. --- binutils-1.8.x-amiga/strip.c    Wed Sep 22 12:45:43 1993
  3065. ***************
  3066. *** 72,76 ****
  3067.   /* If BSD, we can use `ftruncate'.  */
  3068.   
  3069. ! #ifndef USG
  3070.   #define HAVE_FTRUNCATE
  3071.   #endif
  3072. --- 72,76 ----
  3073.   /* If BSD, we can use `ftruncate'.  */
  3074.   
  3075. ! #if !defined(USG) && !defined(MCH_AMIGA)
  3076.   #define HAVE_FTRUNCATE
  3077.   #endif
  3078. ***************
  3079. *** 288,293 ****
  3080. --- 288,295 ----
  3081.   
  3082.     /* Handle any signal that came in while they were deferred.  */
  3083. + #ifndef MCH_AMIGA
  3084.     if (delayed_signal)
  3085.       kill (getpid (), delayed_signal);
  3086. + #endif
  3087.   }
  3088.   
  3089. ***************
  3090. *** 929,932 ****
  3091. --- 931,935 ----
  3092.   
  3093.   #ifdef USG
  3094. + #ifndef MCH_AMIGA
  3095.   
  3096.   rename (from, to)
  3097. ***************
  3098. *** 941,944 ****
  3099. --- 944,948 ----
  3100.   }
  3101.   
  3102. + #endif
  3103.   #endif
  3104.   
  3105.